Advertisement
theo830

code

Jun 6th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <list>
  3. using namespace std;
  4. typedef long long ll;
  5. bool find(list<ll>b,ll n){
  6. list<ll>w(b);
  7. ll i=1;
  8. ll f=0;
  9. while(i < n){
  10. f+=w.front();
  11. w.pop_front();
  12. if(f < 0){
  13. return 0;
  14. break;
  15. }
  16. i++;
  17. }
  18. return 1;
  19. }
  20. int main(void){
  21. ios_base::sync_with_stdio(0);
  22. cin.tie(0);
  23. cout.tie(0);
  24. ll n;
  25. cin>>n;
  26. list<ll>b;
  27. ll c;
  28. ll g=0;
  29. bool w=0;
  30. for(ll i=0;i<n;i++){
  31. cin>>c;
  32. if(c < 1){
  33. w = 1;
  34. }
  35. g+=c;
  36. b.push_back(c);
  37. }
  38. ll o=0;
  39. ll temp;
  40. if(w){
  41. for(int i=0;i<n;i++){
  42. if(g <= 0){
  43. break;
  44. }
  45. if(find(b,n)){
  46. o++;
  47. }
  48. temp = b.front();
  49. b.pop_front();
  50. b.push_back(temp);
  51. }
  52. cout<<o;
  53. }
  54. else{
  55. cout<<n;
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement