artemgf

Grand Theft Array V

May 8th, 2017
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #define _USE_MATH_DEFINES
  2. #include <iostream>
  3. #include <conio.h>
  4. #include <string>
  5. #include <set>
  6. #include <map>
  7. #include <algorithm>
  8. #include <string>
  9. #include <math.h>
  10. #include <vector>
  11. #include <cmath>
  12. #include <sstream>
  13.  
  14. using namespace std;
  15.  
  16. int main()
  17. {
  18.     long long n, suma=0, sumb=0, a, b, prom;
  19.     long long arry[100001];
  20.  
  21.     cin >> n;
  22.  
  23.     for (int i = 1; i <= n; i++)
  24.     {
  25.         cin >> prom;
  26.         arry[i] = prom;
  27.     }
  28.  
  29.     cin >> a >> b;
  30.  
  31.     if (a < b)
  32.     {
  33.         for (int i = 1; i <= n; i++)
  34.         {
  35.             if (i <= (a+b)/2)
  36.                 suma += arry[i];
  37.             else
  38.                 sumb += arry[i];
  39.         }
  40.     }
  41.     else
  42.         if(a>b)
  43.             for (int i = 1; i <= n; i++)
  44.             {
  45.                 if (i <= ceil((a+b) / 2.0) - 1)
  46.                     sumb += arry[i];
  47.                 else
  48.                     suma += arry[i];
  49.             }
  50.         else
  51.         {
  52.             for (int i = 1; i <= n; i++)
  53.             {
  54.                 if (i < a)
  55.                     sumb += arry[i];
  56.                 else
  57.                     if (i > a)
  58.                         suma += arry[i];
  59.             }
  60.             if (suma >= sumb)
  61.                 suma = suma + arry[a];
  62.             else
  63.             {
  64.                 prom = suma;
  65.                 suma = sumb + arry[a];
  66.                 sumb = prom;
  67.             }
  68.         }
  69.  
  70.     cout << suma << endl << sumb;
  71.    
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment