Advertisement
thaihoa123

123

Jan 23rd, 2020
461
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4. int a[100000],f[100000],f1[100000];
  5. int main ()
  6. {
  7. int t_case;
  8. cin >> t_case;
  9. for(int k=1;k<=t_case;++k)
  10. {
  11. int n,quang_sum=0,thuan_sum;
  12. cin >> n;
  13. for(int j=1;j<=n;++j)
  14. {
  15. cin >> a[j];
  16. quang_sum +=a[j];
  17. }
  18. int l=1;
  19. int r=n-1;
  20. f[0]=0;
  21. for(int i=l;i<=r;++i)
  22. {
  23. f[i]=f[i-1]+a[i];
  24. }
  25. int maxsum1=-100000;
  26. for(int i=l;i>=r;++i)
  27. {
  28. maxsum1 = max(maxsum1,f[i]);
  29. }
  30. // tim tong lon nhat cua doan [1;n-1]
  31. l=2;
  32. r=n;
  33. f1[0]=0;
  34. f1[1] = 0;
  35. for(int i=l;i<=r;++i)
  36. {
  37. f1[i]=f1[i-1]+a[i];
  38. }
  39. int maxsum2=-100000;
  40. for(int i=l;i<=r;++i)
  41. {
  42. maxsum2 = max(maxsum2,f1[i]);
  43. }
  44. // tim tong lon nhat cua doan [2;n]
  45. thuan_sum = max(maxsum1,maxsum2);
  46. // trong 2 cai tong vua tim duoc cai nao lon nhat thi gan no = thuan_sum
  47. if(quang_sum <= thuan_sum)
  48. {
  49. cout << "Tet khong co gi vui" << "\n";
  50. }
  51. else if(quang_sum > thuan_sum)
  52. {
  53. cout << "Happy New Year" << "\n";
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement