What's wrong with this code for 1985C — Good Prefixes? Any help would be appreciated.

Revision en1, by Arcer, 2026-01-10 20:09:58

I was just trying to solve 1985C - Good Prefixes using C++ and this is my code, i dont know why but this code doesnt work for specific testcases. Please help me find the mistake.

My code:

#include <bits/stdc++.h>
using namespace std;

void solve() {
    int n, c = 0;
    cin >> n;
    vector<long long int> v(n), s(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        if (i == 0) s[i] = v[i];
        else s[i] = s[i - 1] + v[i];
    }
    for (int i = 1; i < n; i++) if (find(v.begin(), v.begin() + i + 1, s[i] / 2) != v.end() && s[i] % 2 == 0) c++;
    if (v[0] == 0) c++;
    cout << c << endl;
}

int main() {
    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
}

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English Arcer 2026-01-10 20:09:58 826 Initial revision (published)