Warm up : Laddu

I am not able to understand why is this code giving me TLE, can anyone please explain.

#include <bits/stdc++.h>
using namespace std;

int main() {
    int t;
	cin>>t;
	while(t--){
	    int activities;
	    string origin;
	    cin>>activities;
	    cin>>origin;
	    long long int ans = 0;
	    while(activities--){
	        string contest;
	        cin>>contest;
	        
	        if(contest == "CONTEST_WON"){
	            int x;
	            cin>>x;
	            ans += 300;
	            if(x<=20) 
	                ans += (20-x);
	        }
	        else if(contest == "TOP_CONTRIBUTOR"){
	            ans += 300;
	        }
	        else if(contest == "BUG_FOUND"){
	            int x;
	            cin>>x;
	            ans += x;
	        }
	        else if(contest == "CONTEST_HOSTED"){
	            ans += 50;
	        }
	    }
	    
	    if(origin == "INDIAN"){
	        cout<<ans/200<<endl;
	    }
	    else cout<<ans/400<<endl;
	}
	return 0;
}

This is why you have to give context. Because it took me a while to figure out that your program is right, but you just ran it without custom input. If you had said that it times out when you “run” it on CodeChef IDE, it would have been so much easier.

2 Likes

Thanks