Author: Praveen Dhinwa
Tester: Kevin Atienza
Translators: Sergey Kulik (Russian), Team VNOI (Vietnamese) and Hu Zecong (Mandarin)
Editorialist: Kevin Atienza

Cakewalk

### PREREQUISITES:

Loops, integer division

### PROBLEM:

Given the history of a user’s activities in CodeChef and other relevant information regarding the new Laddu Accrual System, how many months can he/she redeem laddus?

### EXPLANATION:

This is the easiest problem in the contest. A straightforward implementation will do. The idea is to first count the amount of laddus the user has accumulated, and then simply divide by 200 or 400, depending on the origin.

Here are sample implementations.

C++:

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
int cases;
cin >> cases;
while (cases--) {
int activities, points = 0;
string origin;
cin >> activities >> origin;
while (activities--) {
string kind;
cin >> kind;
if (kind == "CONTEST_WON") {
int rank;
cin >> rank;
int bonus = max(0, 20 - rank);
points += 300 + bonus;
} else if (kind == "TOP_CONTRIBUTOR") {
points += 300;
} else if (kind == "BUG_FOUND") {
int severity;
cin >> severity;
points += severity;
} else if (kind == "CONTEST_HOSTED") {
points += 50;
}
}
cout << points / (origin == "INDIAN" ? 200 : 400) << endl;
}
}


Python:

for cas in xrange(input()):
n, origin = raw_input().strip().split()
points = 0
for i in xrange(int(n)):
data = raw_input().strip().split()
kind = data[0]
if kind == 'CONTEST_WON':
rank = int(data[1])
bonus = max(0, 20 - rank)
points += 300 + bonus
elif kind == 'TOP_CONTRIBUTOR':
points += 300
elif kind == 'BUG_FOUND':
severity = int(data[1])
points += severity
elif kind == 'CONTEST_HOSTED':
points += 50

print points / (200 if origin == 'INDIAN' else 400)


# Common mistakes

Being the easiest one, this attracts the most number of participants, and probably also the most number of mistakes. Here are the ones I found while looking at incorrect answers:

• Opening a file. This causes “Time Limit Exceeded” or “Wrong Answer”. Remember that input is taken from stdin, and output should be written in stdout. No file input/output should be done. If you want to test your code locally using a file, use redirection, e.g. my_program < my_input_file > my_output_file which means "Run my_program with input from my_input_file, and write the output in my_output_file".
• Printing unnecessary output. Remember that your answer will only get accepted if it exactly matches the intended output, character by character. So please don’t print anything like Enter the number of test cases:, because that is a part of the output. If you want to print auxiliary code, print to stderr instead, but don’t overdo it, otherwise you might get “Time Limit Exceeded” or “Output Limit Exceeded”.
• Some common coding errors, like writing laddus = 300 instead of laddus += 300.
• Problems with “Bonus” computation, like forgetting that bonus = 0 when rank > 20, or forgetting to add 300 if rank > 20.
• Not allocating enough bytes for strings in languages with picky string input, like C. It’s generally a good idea to allocate more than needed, e.g. even though the longest string is TOP_CONTRIBUTOR which has 15 characters, you should allocate, say, 21 (or even 100) characters just to be safe.
• Incorrectly reading the input. One example I found is forgetting that activities and origin are found in the same line. You should pay careful attention to the input format.

These mistakes are typical when you’re still just starting programming, and programming contests. If you didn’t get accepted, don’t worry! Everyone starts somewhere, and I’m sure with more practice you’ll encounter these problems less often.

### Time Complexity:

O(\text{activities})

### AUTHOR’S AND TESTER’S SOLUTIONS:

1 Like

I am unable to submit my solution. There seems to be a bug in the service. Can you please help?

#include
#include
using namespace std;
int main()
{
int t;
cin>>t;
for(int i=0;i<t;i++)
{
int n,tot=0,months;
string s;
cin>>n>>s;
for(int j=0;j<n;j++)
{
string activity;
int amt=0;
cin>>activity;
if(activity==“CONTEST_WON”)
{ int rank;
cin>>rank;
if(rank<20)
amt=300+20-rank;
else
amt=300;

			}
else if(activity=="TOP_CONTRIBUTOR")
amt=300;
else if(activity=="BUG_FOUND")
{int sev;
cin>>sev;
amt=sev;
}
else
amt=50;
tot=tot+amt;

}

if(s=="INDIAN")
months=tot/200;
else
months=tot/400;
cout<<months;

cout<<"\n";
}


return 0;
}

https://www.codechef.com/viewsolution/10579515.My code is giving the exact output required in the correct format.Kindly look into this @admin

What is wrong with this code:
#include<stdio.h>
int main(){
int t,i,a,j,l,m;
char o[20],act[20];
scanf("%d",&t);
for(i=1;i<=t;i++){
l=0;
scanf("%d %s",&a,&o);
for(i=1;i<=a;i++){
scanf("%s",&act);
if(strcmp(act,“CONTEST_WON”)==0){
int rank;
scanf("%d",&rank);
if(rank>20){
l=l+300;
}
else{
l=l+300+20-rank;
}
}
if(strcmp(act,“TOP_CONTRIBUTOR”)==0){
l=l+300;
}
if(strcmp(act,“BUG_FOUND”)==0){
int sev;
scanf("%d",&sev);
l=l+sev;
}
if(strcmp(act,“CONTEST_HOSTED”)==0){
l=l+50;
}

}
if(strcmp(o,"INDIAN")==0){
m=l/200;
}
else{
m=l/400;
}
printf("%d\n",m);


}
return 0;
}

i think the complexity would be O(n2) as thr are two while loops
one of test cases and other of activities

It is written for one test case.

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

I have no idea why it is
Plz help!