哪位大佬能帮蒟蒻改一下?(前缀和+双指针)
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 10;
int n, s, a[N], sum[N];
signed main() {
cin >> n >> s;
for (int i = 1; i <= n; ++i)
cin >> a[i];
for (int i = 1; i <= n; ++i)
sum[i] = a[i] + sum[i - 1];
s %= sum[n];
if (s == 0) {
cout << "Yes" << endl;
return 0;
}
int l = 1, r = n;
while (l <= r) {
int tot = sum[r] - sum[l - 1];
if (tot == s) {
cout << "Yes" << endl;
return 0;
} else if (tot < s) r--;
else l++;
}
cout << "No" << endl;
return 0;
}