Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int main()
- {
- ios_base::sync_with_stdio(false);
- int n;
- cin >> n;
- vector<int> v(n);
- for(int &x : v) {
- cin >> x;
- }
- int L = 0, R = n - 1;
- int ret =0 ;
- while(L <= R) {
- if(v[L] == v[R]) {
- ++L;
- --R;
- continue;
- }
- int a = 0;
- for(int i = L; i < R; i++) {
- a += v[i];
- int b = 0;
- bool ok = false;
- for(int j = R; j > i; j--) {
- b += v[j];
- if(a == b) {
- // L = i + 1;
- // R = j - 1;
- ok = true;
- // cout << L + 1 << " " << R + 1 << endl;
- // cout << i + 1 << " " << j + 1 << endl;
- ret += abs(L - i) + abs(R - j);
- L = i + 1;
- R = j - 1;
- break;
- }
- }
- if(ok) {
- break;
- }
- }
- }
- cout << ret << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement