Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("ssm.in");
- ofstream fout("ssm.out");
- int main()
- {
- int n,x;
- fin>>n>>x;
- int bg,ed,poz;
- long long s,smax;
- s=smax=x;
- bg=ed=poz=1;
- if(s<0)
- {
- s=0;
- poz=2;
- }
- for(int i=2;i<=n;i++)
- {
- fin>>x;
- s+=x;
- if(smax<s)
- {
- smax=s;
- bg=poz;
- ed=i;
- }
- if(s<0)
- {
- s=0;
- poz=i+1;
- }
- }
- fout<<smax<<" "<<bg<<" "<<ed<<"\n";
- fin.close();
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment