- 2023/04/15 前缀和差分算法-随堂测验
不是暴力 70分
- 2023-4-15 10:55:47 @
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;
int n, a[MAXN], x, y;
int main(){
scanf("%d", &n);
for (int i=1;i<=n;i++){
scanf("%d", &a[i]);
y += a[i];
}
int ans = 10001;
for (int i = 1; i <= n; i++) {
x += a[i];
y -= a[i];
ans = min(abs(x - y),ans);
}
cout << ans << endl;
return 0;nocopy
}
0 comments
No comments so far...