提交时间:2024-04-20 12:03:01

运行 ID: 45807

#include <bits/stdc++.h> using namespace std; int main() { float sum = 0; int n, num[100]; cin >> n; for (int i = 0; i < n; i++) { cin >> num[i]; sum += num[i]; } int c = 0, min; for (int i = 0; i < n; i++) { c += num[i]; if (c > sum / 2.0) { min = c - (sum - c); c = c - num[i]; if (min > sum - c - c) min = sum - c - c; break; } } cout << min; return 0; }