Bestcoder Round #4 (Happy three friends-greedy)

Source: Internet
Author: User


Happy three Friends
Time limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 934 Accepted Submission (s): 738


Problem Description
Dong-hao, Grandpa Shawn, Beautful-leg Mzry is good friends. One day, they want to play a game. There is 6 numbers on the table. Firstly, Dong-hao can change the order of 6 numbers. Secondly, Grandpa Shawn take the first one and the last one, sum them up as his scores. Thirdly, Beautiful-leg Mzry take all of 3 numbers from the last 4 numbers, and sum them up as his scores. Finally, if Grandpa Shawn ' s score is larger than Beautiful-leg Mzry ' s, Granpa Shawn wins! If Grandpa Shawn ' s score is smaller than Beautiful-leg Mzry ' s, Granpa Shawn loses. If the scores is equal, there is a tie. Nowadays, it ' s really sad that Grandpa Shawn loses he love. So Dong-hao wants him-to-win (not even tie). You have a to-tell Dong-hao whether he can achieve he goal.
Input
There is a number T shows there is t test cases below. (T <= 50) For each test case, there is 6 numbers AI (1 <= ai <= 100).
Output
If Dong-hao can achieve his goal, output "Grandpa Shawn is the winner!" If he can not and output "what a sad story!"
Sample Input
31 2 3 3 2 22 2 2 2 2 21 2 2 2 3 4
Sample Output
What a sad story! What a sad story! Grandpa Shawn is the winner! Hint For the first test case, {3, 1, 2, 2, 2, 3} Grandpa Shawn can take 6 at most. But the Beautiful-leg Mzry can take 6 too. So there is a tie. For the second Test cases, Grandpa Shawn loses. For the last one, Dong-hao can arrange the numbers as {3, 2, 2, 2, 1, 4}, Grandpa Shawn can take 7, but beautiful- Leg Mzry can take 6 at the most. So Grandpa Shawn wins!

Put the maximum of 2 directly outside, Beautiful-leg Mzry the rest of the 3 to take the largest


#include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> #include < functional> #include <iostream> #include <cmath> #include <cctype> #include <ctime>using namespace std; #define for (I,n) for (int. i=1;i<=n;i++) #define FORK (I,k,n) for (int. i=k;i<=n;i++) #define REP (I,n) for (int i=0;i<n;i++) #define ForD (I,n) for (int. i=n;i;i--) #define REPD (I,n) for (int. i=n;i>=0;i--) #define FORP (x) for ( int p=pre[x];p; p=next[p]) #define LSON (x<<1) #define Rson ((x<<1) +1) #define MEM (a) memset (A,0,sizeof (a)); Define Memi (a) memset (A,127,sizeof (a)), #define MEMI (a) memset (A,128,sizeof (a)), #define INF (2139062143) #define F ( 100000007) #define MAXN () #define MAXM () long long mul (long long A,long long B) {return (a*b)%F;} Long Long (long A,long long B) {return (a+b)%F;} Long Long sub (long A,long long B) {return (a-b+ (a)/f*f+f)%F;} typedef long Long Ll;int A[7],t;int main () {//freopen ("a.in", "R", stdin);//freopen ("A.out", "w", stdout); cIn>>t;while (t--) {for (i,6) Cin>>a[i];sort (a+1,a+7); if (a[6]+a[5]>a[4]+a[3]+a[2]) cout<< " Grandpa Shawn is the winner! " <<endl;else cout<< "What a sad story!" <<endl;} return 0;}




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.