Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define ll long long
- using namespace std;
- bool check(vector<ll>v,ll val)
- {
- for(auto u:v)
- {
- val+=u;
- if(val<=0) return false;
- }
- return true;
- }
- int main()
- {
- int t;
- cin>>t;
- while(t--)
- {
- ll n;
- cin>>n;
- vector<ll>v(n);
- for(int i=0;i<n;i++) cin>>v[i];
- ll l=0,r=1e14,ans=1;
- while(l<=r)
- {
- ll mid=(l+r)/2;
- if(check(v,mid))
- {
- ans=mid;
- r=mid-1;
- }
- else l=mid+1;
- }
- cout<<ans<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement