제출 #675981

#제출 시각아이디문제언어결과실행 시간메모리
675981as111Kas (COCI17_kas)C++14
70 / 100
378 ms353228 KiB
#include <iostream> #define MAXN 500 #define MAX 100000 using namespace std; int N; int notes[MAXN + 5]; int dp[MAXN + 5][2*MAX + 5]; // for first i banknotes, difference between 2 sums + MAX, diff<MAX means negative int main() { cin >> N; int total = 0; for (int i = 1; i <= N; i++) { cin >> notes[i]; total += notes[i]; fill(dp[i], dp[i] + 2*MAX, MAX + 1); } for (int i = 0; i <= N; i++) fill(dp[i], dp[i] + 2*MAX, MAX + 1); dp[0][MAX] = 0; for (int i = 0; i < N; i++) { for (int k = -total; k <= total; k++) { int j = k + MAX; dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + notes[i + 1]); // add to remaining dp[i + 1][j + notes[i + 1]] = min(dp[i + 1][j + notes[i + 1]], dp[i][j]); // add to first person dp[i + 1][j - notes[i + 1]] = min(dp[i + 1][j - notes[i + 1]], dp[i][j]); // add to second } } cout << ((total-dp[N][MAX])/2+dp[N][MAX]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...