int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t;
cin>>t;
while(t--){
long long time=0;
long long min=INT_MAX;
long long n,a,b,c;
cin>>n>>a>>b>>c;
if(b-a>=0){
time=b-a+c;}
else if(b-a<0){
time=a-b+c;
}
long long i=0;
while(n--){
long long a[n];
cin>>a[i];
time=time+2*a[i];
if(time<=min){
min=time;
}
else if(time>INT_MAX){
min=time;
}
time=time-2*a[i];
i++;
}
cout<<min-2*b<<endl;
}
}
using namespace std;
int main()
{
long long int x,uu,t,n,a,i,b,c;
long long int f[100];
long long p[100];
cin>>t;
while(t–)
{
cin>>n>>a>>b>>c;
for(i=0;i<n;i++)
{
long long int element;
cin>>element;
p[i]=element;
int distance=abs(element-b);
f[i]=distance;
}
sort(f,f+n);
long long int fd=f[0];
int flag=0;
uu=0;
for(int it=0;it<n;i++)
{
#include<bits/stdc++.h> #define REP(i,n) for (int i = 0; i < n; i++) #define mod 1000000007 #define pb push_back #define ff first #define ss second #define ii pair<int,int> #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
Here’s my code- It’s working perfecting fine for the given constraints in my machine but codechef says wrong answer(WA). Can anyone explain what’s wrong with my code?
Then why it is working completely fine on my machine and even on codechef when I provide custom input(same inputs given in the question) and even answer is correct.
int main() {
// your code goes here
int T;
cin>>T;
while(T–)
{
long long int N,a,b,c;
cin>>N>>a>>b>>c;
long long int F[N],mi=99999999999999999,k=0;
for(int i=0;i<N;i++)
{
cin>>F[i];
if(abs(F[i]-b)<mi)
{
k=F[i];mi=abs(F[i]-b);
}
}long long int re=mi+abs(k-a)+c;
cout<<re<<endl;
long int choice;
scanf("%d", &choice); // number of testcases
long long int n, alice, bob, time;
while (choice)
{
scanf("%ld", &n);
scanf("%lld", &alice);
scanf("%lld", &bob);
scanf("%lld", &time);
long long int friends[n];
for (int i = 0; i < n; i++)
{
scanf("%lld", &friends[i]);
}
long long int min = friends[0];
for (int i = 1; i < n; i++)
{
if (friends[i] < min)
{
min = friends[i];
}
}
long long int total_time = 2 * (min - alice) + time + (bob - alice);
printf("%lld", total_time);
choice--;
}
return 0;
@ssjgz Please look at my code and correct me the given test cases are passed but when i’m trying to submit it i’m getting WA
public static void main (String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int test = Integer.parseInt(br.readLine());
while(test-- > 0){
String str = br.readLine();
String[] arr = str.split("\s+");
int n = Integer.parseInt(arr[0]);
int a = Integer.parseInt(arr[1]);
int b = Integer.parseInt(arr[2]);
int c = Integer.parseInt(arr[3]);
str = br.readLine();
arr = str.split("\s+");
long result = Integer.MAX_VALUE;
long UP = Integer.MAX_VALUE;
long DOWN = Integer.MIN_VALUE;
while(n > 0){
int l = Integer.parseInt(arr[–n]);
UP= (Math.abs(l-a))+(Math.abs(l-b));
DOWN = (Math.abs(a-l))+(Math.abs(b-l));
result = Math.min((UP+c),(DOWN+c));
}
System.out.println(result);
}
}
int main()
{
int t;
long long int N,a,b,c,x;
cin>>t;
for(long long int i=0;i<t;i++)
{
cin>>N>>a>>b>>c;
long long int A[N],x;
for(long long int k=0;k<N;k++)
{
cin>>A[k];
}
long long int min = abs(b - A[0]);
long long int f = A[0];
for(long long int m=1;m<N;m++)
{
x=abs(b-A[m]);
if(min>x)
{
f=A[m];
}
}
long long int y = abs(f - b) + c + abs(f - a);
cout<<y<<endl;
}
return 0;
}