Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <list>
- using namespace std;
- typedef long long ll;
- bool find(list<ll>b,ll n){
- list<ll>w(b);
- ll i=1;
- ll f=0;
- while(i < n){
- f+=w.front();
- w.pop_front();
- if(f < 0){
- return 0;
- break;
- }
- i++;
- }
- return 1;
- }
- int main(void){
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- ll n;
- cin>>n;
- list<ll>b;
- ll c;
- ll g=0;
- bool w=0;
- for(ll i=0;i<n;i++){
- cin>>c;
- if(c < 1){
- w = 1;
- }
- g+=c;
- b.push_back(c);
- }
- ll o=0;
- ll temp;
- if(w){
- for(int i=0;i<n;i++){
- if(g <= 0){
- break;
- }
- if(find(b,n)){
- o++;
- }
- temp = b.front();
- b.pop_front();
- b.push_back(temp);
- }
- cout<<o;
- }
- else{
- cout<<n;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement