Can anyone help me why the following code is giving TLE? (TOWIN)

#include<bits/stdc++.h>
#include
using namespace std;
//#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL)
#define endl “\n”
#define ll long long

int main(){
IOS;
int t;
cin>>t;
while(t–){
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n,greater());
int p1=0,p2=0;
for(int i=0;i<n;i++){
if(i==0){
p1=p1+a[i];
}
else if(i==1 || i==2){
p2=p2+a[i];
}
else if(i%2!=0){
p1=p1+a[i];
}
else if(i%2==0){
p2=p2+a[i];
}
}
if(p1>p2){
cout<<“first”<<endl;
}
else if(p2>p1){
cout<<“second”<<endl;
}
else{
cout<<“draw”<<endl;
}
}
}

Please either format your code or (better!) link to your submission - the forum software has mangled it and it won’t compile! :slight_smile:

Also: what Problem are you trying to solve? :slight_smile:

This is link to the problem. Go to My Submissions on the problem page and click view.

1 Like

https://www.codechef.com/viewsolution/36706785

Make the following change:

ll p1=0,p2=0;

Your submission with ll gives Correct Answer.

That’s WA, not TLE.

1 Like