Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int INF=1e9;
  4. int mx=-INF;
  5. int main(){
  6.  
  7. int n;
  8. scanf("%d",&n);
  9. int ar[n+1];
  10. for(int i=1;i<=n;i++){
  11. scanf("%d",&ar[i]);
  12. }
  13.  
  14. vector <int> keep,ans;
  15. for(int i=1;i<=n;i++){
  16. int cnt=0;
  17. for(int j=i;j<=n;j++){
  18. cnt=cnt+ar[j];
  19. keep.push_back(ar[j]);
  20. if(cnt>mx) {
  21. mx=cnt;
  22. if(ans.size()>0) ans.clear();
  23. for(int j=0;j<keep.size();j++) ans.push_back(keep[j]);
  24. }
  25. }
  26. keep.clear();
  27. }
  28. if(mx<=0) printf("Empty sequence");
  29. else {
  30. for(int i=0;i<ans.size();i++) printf("%d ",ans[i]);
  31. printf("\n%d",mx);
  32. }
  33.  
  34.  
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement