Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int a[100000],f[100000],f1[100000];
- int main ()
- {
- int t_case;
- cin >> t_case;
- for(int k=1;k<=t_case;++k)
- {
- int n,quang_sum=0,thuan_sum;
- cin >> n;
- for(int j=1;j<=n;++j)
- {
- cin >> a[j];
- quang_sum +=a[j];
- }
- int l=1;
- int r=n-1;
- f[0]=0;
- for(int i=l;i<=r;++i)
- {
- f[i]=f[i-1]+a[i];
- }
- int maxsum1=-100000;
- for(int i=l;i>=r;++i)
- {
- maxsum1 = max(maxsum1,f[i]);
- }
- // tim tong lon nhat cua doan [1;n-1]
- l=2;
- r=n;
- f1[0]=0;
- f1[1] = 0;
- for(int i=l;i<=r;++i)
- {
- f1[i]=f1[i-1]+a[i];
- }
- int maxsum2=-100000;
- for(int i=l;i<=r;++i)
- {
- maxsum2 = max(maxsum2,f1[i]);
- }
- // tim tong lon nhat cua doan [2;n]
- thuan_sum = max(maxsum1,maxsum2);
- // trong 2 cai tong vua tim duoc cai nao lon nhat thi gan no = thuan_sum
- if(quang_sum <= thuan_sum)
- {
- cout << "Tet khong co gi vui" << "\n";
- }
- else if(quang_sum > thuan_sum)
- {
- cout << "Happy New Year" << "\n";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement