https://cses.fi/problemset/task/1661

#include
#include
using namespace std;

vector arr_comp(int num) {

vector<int> arr(num+1);
arr[0] = 0;

for (int i = 1; i < num+1; i++) {
	cin >> arr[i];
}
return arr;

}

void result(int num, vector arr, int compare) {

vector<int> res(num + 1);
res[0] = 0; 
int sum = 0;
for (int i = 1; i < num + 1; i++) {
	res[i] = res[i - 1] + arr[i];

	if (res[i] == compare) { sum++; }
}
cout << sum;

}

int main() {
int num; cin >> num;
int compare; cin >> compare;

result(num, arr_comp(num), compare);

} this is my solution to it, i know it is flawed and what frustrates me is that i don’t know how to make it work (just learned about Prefix sums). how can i even get better in coming up with flawless (or at least less flawed ) solutions :neutral_face:? like how to get that mathematical thinking they’re talking about?