Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int maxN = 2000;
- long long a[maxN];
- bool yes (int n,long long hp) {
- for (int i = 1; i <= n; ++i) {
- hp += a[i];
- if (hp < 1) return false;
- }
- return true;
- }
- int main () {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int T;
- cin >> T;
- for (int test_case = 1; test_case <= T; ++test_case) {
- int n;
- cin >> n;
- for (int i = 1; i <= n; ++i) cin >> a[i];
- long long l = 0,r = 1e9;
- long long res = 0;
- while (l <= r) {
- long long hp = (l + r) / 2;
- if (yes(n,hp)) {
- res = hp;
- r = hp - 1;
- } else {
- l = hp + 1;
- }
- }
- cout << res << '\n';
- }
- //~ cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement