Advertisement
a53

maxsim

a53
May 1st, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #include <fstream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. ifstream f("maxsim.in");
  6. ofstream g("maxsim.out");
  7.  
  8. int main()
  9. {
  10. long int v[1000],j,x,y,poz,i,n,s=0,smax=-1;
  11. f>>n;
  12. for(i=1;i<=n;i++)
  13. f>>v[i];
  14. for(i=1,j=n;i<=j;i++,j--)
  15. {
  16. s+=v[i]+v[j];
  17. if(s>smax)
  18. {
  19. smax=s;
  20. poz=i;
  21. x=i;
  22. y=j;
  23. }
  24. else if(s==smax)
  25. {
  26. if(i<poz)
  27. {
  28. poz=i;
  29. x=i;
  30. y=j;
  31. }
  32. }
  33. s=0;
  34. }
  35. g<<smax<<' '<<x<<' '<<y;
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement