Advertisement
josiftepe

Untitled

Mar 6th, 2021
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     ios_base::sync_with_stdio(false);
  9.     int n;
  10.     cin >> n;
  11.     vector<int> v(n);
  12.     for(int &x : v) {
  13.         cin >> x;
  14.     }
  15.     int L = 0, R = n - 1;
  16.     int ret =0 ;
  17.    
  18.     while(L <= R) {
  19.         if(v[L] == v[R]) {
  20.             ++L;
  21.             --R;
  22.             continue;
  23.         }
  24.         int a = 0;
  25.         for(int i = L; i < R; i++) {
  26.             a += v[i];
  27.            
  28.             int b = 0;
  29.             bool ok = false;
  30.             for(int j = R; j > i; j--) {
  31.                 b += v[j];
  32.                 if(a == b) {
  33. //                    L = i + 1;
  34. //                    R = j - 1;
  35.                     ok = true;
  36. //                    cout << L + 1 << " " << R + 1 << endl;
  37. //                    cout << i + 1 << " " << j + 1 << endl;
  38.                     ret += abs(L - i) + abs(R - j);
  39.                     L = i + 1;
  40.                     R = j - 1;
  41.                     break;
  42.                 }
  43.             }
  44.             if(ok) {
  45.                 break;
  46.             }
  47.         }
  48.     }
  49.     cout << ret << endl;
  50.     return 0;
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement