Description
Background
Bill, Steve and Linus participate in programming contests just like the one you're competing in right now. They have different strategies and we’d like to find out whose strategy is the best.
Problem
Bill simply solves the problems in the order he gets them from the contest organizers. Steve first reads all the problems and then solves them in increasing order of difficulty. Linus also reads all problems first, but he's quite ambitious and thus solves them in decreasing order of difficulty.
The difficulty of a problem is measured in minutes it takes the guys to solve it. We have collected statistics and we've consulted the oracle Larry so we know for all kinds of problems how long the guys will need. We have also found out that the three of them always need the same time for each problem (which depends on the difficulty of the problem), so they only differ by their strategies.
For several contests, we'd like you to tell us the winner, the number of problems he solved and his score. The score for a single problem is the time in minutes from start of the contest until you solve it. The overall score is the sum of scores of the problems you solved. The guys never make mistakes so you don't have to deal with penalties. The winner is the one who solved the most problems, and in case of a tie, the one with the lowest score. If there's still a tie, then they agree that Steve wins because he always brings delicious apple pie.
Bill, Steve and Linus participate in programming contests just like the one you're competing in right now. They have different strategies and we’d like to find out whose strategy is the best.
Problem
Bill simply solves the problems in the order he gets them from the contest organizers. Steve first reads all the problems and then solves them in increasing order of difficulty. Linus also reads all problems first, but he's quite ambitious and thus solves them in decreasing order of difficulty.
The difficulty of a problem is measured in minutes it takes the guys to solve it. We have collected statistics and we've consulted the oracle Larry so we know for all kinds of problems how long the guys will need. We have also found out that the three of them always need the same time for each problem (which depends on the difficulty of the problem), so they only differ by their strategies.
For several contests, we'd like you to tell us the winner, the number of problems he solved and his score. The score for a single problem is the time in minutes from start of the contest until you solve it. The overall score is the sum of scores of the problems you solved. The guys never make mistakes so you don't have to deal with penalties. The winner is the one who solved the most problems, and in case of a tie, the one with the lowest score. If there's still a tie, then they agree that Steve wins because he always brings delicious apple pie.
Input
The first line contains the number of scenarios. Each scenario describes one contest and its first line tells you how long the contest lasts (in minutes, from 30 to 1440) and the number of problems (from 3 to 24). In a second line
you'll get the difficulties of the problems, as explained above they tell you how many minutes (from 1 to 600) the guys need in order to solve the problems.
Output
The output for every scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. Then print a single line telling who wins, the number of problems he solves and his score. Use the
exact format as shown below in the sample output, even if the winner only solves 0 or 1 problems. Terminate the output for the scenario with a blank line.
Sample Input
2 180 6 23 42 170 33 7 19 60 2 43 17
Sample Output
Scenario #1: Steve wins with 5 solved problems and a score of 288. Scenario #2: Steve wins with 2 solved problems and a score of 77.
#include <iostream> #include <algorithm> using namespace std; int cmp2(int a,int b) { return a>b; } int cmp1(int a,int b) { return a<b; } int main() { int T,cases=1; cin>>T; while(T--) { int time,num; int A[25]={0},B[25]={0},C[25]={0},a[4][2]={0}; cin>>time>>num; for(int i=1;i<=num;i++) { cin>>A[i]; B[i]=A[i]; C[i]=A[i]; } sort(B+1,B+num+1,cmp1); sort(C+1,C+1+num,cmp2); for(int i=1;i<=num;i++) { if(A[i]+A[i-1]<=time) { A[i]=A[i-1]+A[i]; a[1][0]=A[i]+a[1][0]; a[1][1]++; } else break; } for(int i=1;i<=num;i++) { if(B[i]+B[i-1]<=time) { B[i]=B[i]+B[i-1]; a[2][0]=B[i]+a[2][0]; a[2][1]++; } else break; } for(int i=1;i<=num;i++) { if(C[i]+C[i-1]<=time) { C[i]=C[i-1]+C[i]; a[3][0]=C[i]+a[3][0]; a[3][1]++; } else break; } int index=0,maxs=0; for(int i=1;i<=3;i++) if(a[i][1]>=maxs) { maxs=a[i][1]; index=i; } if(a[1][1]==a[2][1]&&a[2][1]==a[3][1]) { index=2; } cout<<"Scenario #"<<cases++<<":"<<endl; if(index==1) cout<<"Bill wins with "<<maxs<<" solved problems and a score of "<<a[1][0]<<"."<<endl; if(index==2) cout<<"Steve wins with "<<maxs<<" solved problems and a score of "<<a[2][0]<<"."<<endl; if(index==3) cout<<"Linus wins with "<<maxs<<" solved problems and a score of "<<a[3][0]<<"."<<endl; if(T!=0) cout<<endl; } return 0; }