|
|
back to boardWA test #7,I don't why,who can help me Posted by aurora 9 Sep 2016 17:52 #include <iostream> using namespace std; int main() { long int n; while (cin >> n) { long b1 = 0, b2 = 0, a[22], sum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } long int k = sum / 2; for(int i=0;i<n-1;i++) for(int j=i+1;j<n;j++) if (a[i] < a[j]) { long int t = a[i]; a[i] = a[j]; a[j] = t; } for (int j = 0; j < n; j++) { if (b1+a[j] <= k) b1 += a[j]; else if (b1 < b2) b1 += a[j]; else b2 += a[j]; } long int x = b2 - b1; if (x < 0) x = -x; cout << x << endl; } return 0; } |
|
|