|
|
вернуться в форумwhy doesn't it work? //took wa5, anybody know test5? #include <iostream> #include <algorithm> using namespace std; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout); #endif int N, W[20] = {0}; int s = 0, r = 0; cin >> N; for(int i = 0; i < N; i++) { cin >> W[i]; s += W[i]; } sort(W, W + N); r = W[N-1]; s -= r; for(int i = N - 2; i >= 0; i--) { if ((r - W[i] >= 0) || ((s + r - 2 * W[i]) >= 0)) r -= W[i]; else r += W[i]; s -= W[i]; } cout << r; return 0; } |
|
|