Niloy007

RPLC - Coke madness

Mar 14th, 2021
860
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. #define Niloy
  3. #define int int64_t
  4. #define MAX (int) 1e6 + 123
  5. #define MOD 1e9
  6. #define pb push_back
  7. #define pairs pair<int, int>
  8. #define vi vector<int>
  9. #define vb vector<bool>
  10. #define vii vector<pairs>
  11. #define lb lower_bound
  12. #define ub upper_bound
  13. #define endl '\n'
  14. #define llu unsigned long long
  15. using namespace std;
  16. /* ----------------------------------------------------------------------------------- */
  17.  
  18. // Input/Output
  19. #define fastInput ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  20. #define all(x) x.begin(), x.end()
  21.  
  22. #define scan(a)           scanf("%lld", &a);
  23. #define scan2(a, b)       scanf("%lld %lld", &a, &b);
  24. #define scan3(a, b, c)    scanf("%lld %lld %lld", &a, &b, &c);
  25. #define scan4(a, b, c, d) scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
  26.  
  27. #define scanD(a)          scanf("%lf", &a);
  28. #define scanD2(a, b)      scanf("%lf %lf", &a, &b);
  29. #define scanD3(a, b, c)   scanf("%lf %lf %lf", &a, &b, &c);
  30. #define scanD4(a, b, c, d)scanf("%lf %lf %lf %lf", &a, &b, &c, &d);
  31.  
  32.  
  33. #define print(a)           printf("%lld\n", a);
  34. #define print2(a, b)       printf("%lld %lld\n", a, b);
  35. #define print3(a, b, c)    printf("%lld %lld %lld\n", a, b, c);
  36. #define print4(a, b, c, d) printf("%lld %lld %lld %lld\n", a, b, c, d);
  37.  
  38. #define printD(a)          printf("%lf\n", a);
  39. #define printD2(a, b)      printf("%lf %lf\n", a, b);
  40. #define printD3(a, b, c)   printf("%lf %lf %lf\n", a, b, c);
  41. #define printD4(a, b, c, d)printf("%lf %lf %lf %lf\n", a, b, c, d);
  42. #define printTwoD(a)       printf("%.2lf\n", a);
  43.  
  44. // File I/O
  45. #define read(x)  freopen(x, "r", stdin);
  46. #define write(x) freopen(x, "w", stdout);
  47.  
  48. // Loops
  49. #define rep(i, a, n) for (int i = a; i < n; i++)
  50. #define REP(i, a, n) for (int i = a; i <= n; i++)
  51. #define rev(i, n, a) for (int i = n - 1; i >= a; i--)
  52. #define REV(i, n, a) for (int i = n; i >= a; i--)
  53. #define inputArray(a,n) rep(i, 0, n) cin >> a[i];
  54. #define copyArray(a,temp,n) rep(i, 0, n) temp[i]=a[i];
  55. #define printArray(a,n) rep(i, 0, n) cout << a[i] << " "; cout << endl;
  56.  
  57. /* ----------------------------------------------------------------------------------- */
  58.  
  59. #define Cases  cout << "Scenario #" << ++Case << ": ";
  60. #define __test int tt; int Case=0; cin >> tt; while(tt--)
  61. #define showTime cerr << "time = " << (clock() / CLOCKS_PER_SEC) << " sec" << '\n';
  62.  
  63. #define dbgA2(A, n, m) {cout<<"--> "<<#A<<" = \n";rep(i, 0, n){rep(j, 0, m){cout<<A[i][j]<<"";}cout<<"\n";}cout<<"\n";}
  64. #define dbgA(A, n) {cout<<" --> "<<#A<<" = (";rep(i, 0, n)cout<<A[i]<<" ";cout<<")\n";}
  65. #define dbg(args...) {string sss(#args);sss+=',';cout<<" --> ";debugger::call(all(sss), args);cout<<"\n";}
  66.  
  67. /* ----------------------------------------------------------------------------------- */
  68.  
  69. int gcd(int n, int m) { return m ? gcd(m, n % m) : n; }
  70. int lcm(int n, int m) { return n / gcd(n, m) * m; }
  71.  
  72. struct debugger {
  73.     typedef string::iterator si;
  74.     static void call(si it, si ed) {}
  75.     template<typename T, typename ... aT>
  76.     static void call(si it, si ed, T a, aT... rest) {
  77.         string b;
  78.         for(; *it!=','; ++it)
  79.             if(*it!=' ')
  80.                 b+=*it;
  81.         cout << b << "=" << a << " ";
  82.         call(++it, ed, rest...);
  83.     }
  84. };
  85.  
  86. /* ----------------------------------------------------------------------------------- */
  87. void input() {
  88. #ifdef Niloy
  89.     read("input.txt");  
  90.     write("output.txt");
  91. #endif
  92. }
  93.  
  94. /* ----------------------------------------------------------------------------------- */
  95.  
  96. int n;
  97. int arr[MAX];
  98.  
  99. bool check(int value) {
  100.     REP(i, 1, n) {
  101.         value += arr[i];
  102.         if (value <= 0) {
  103.             return 0;
  104.         }
  105.     }
  106.     return 1;
  107. }
  108.  
  109. int binarySearch() {
  110.     int l = 1, r = 1e14;
  111.     int ans;
  112.     while (l <= r) {
  113.         int mid = (l + r) >> 1;
  114.         if (check(mid)) {
  115.             ans = mid;
  116.             r = mid - 1;
  117.         } else {
  118.             l = mid + 1;
  119.         }
  120.     }
  121.     return ans;
  122. }
  123.  
  124. void solve() {
  125.     scan(n);
  126.     REP(i, 1, n) {
  127.         scan(arr[i]);
  128.     }
  129.     cout << binarySearch() << endl;
  130. }
  131.  
  132. int32_t main() {
  133.     // input();
  134.     // fastInput;
  135.     // solve();
  136.  
  137.     __test {
  138.         Cases
  139.         solve();
  140.     }
  141.  
  142.     // showTime;
  143.     return 0;
  144. }
  145.  
RAW Paste Data