TEXT 17
Untitled Guest on 17th July 2020 01:02:02 PM
  1. #include <fstream>
  2. using namespace std;
  3. long long i, n, p1, p2, S1=0, S2=0, S3=0, Min=2000000001, Max=-2000000001, x;
  4. int main()
  5. {
  6.     ifstream f("memory002.in");
  7.     f>>n;
  8.     for(i=1; i<=n; i++)
  9.     {
  10.         f>>x;
  11.         S1=S1+x;
  12.         if(x<Min)
  13.         {
  14.             S2=S1;
  15.             Min=x;
  16.         }
  17.         if(x>Max)
  18.         {
  19.             S3=S1;
  20.             Max=x;
  21.         }
  22.     }
  23.     f.close();
  24.     if(S2>S3)
  25.         S1=S2-S3+Max;
  26.     else S1=S3-S2+Min;
  27.     ofstream g("memory002.out");
  28.     g<<S1;
  29.     return 0;
  30. }

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.