Submission #675982

# Submission time Handle Problem Language Result Execution time Memory
675982 2022-12-28T17:47:25 Z as111 Kas (COCI17_kas) C++14
100 / 100
352 ms 392452 KB
#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];
	}
	for (int i = 0; i <= N; i++) fill(dp[i], dp[i] + 2*MAX+5, 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 << (dp[N][MAX]+(total-dp[N][MAX])/2);
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8916 KB Output is correct
2 Correct 5 ms 8916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8916 KB Output is correct
2 Correct 6 ms 8864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8900 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 10452 KB Output is correct
2 Correct 5 ms 11220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 11204 KB Output is correct
2 Correct 6 ms 11220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 28464 KB Output is correct
2 Correct 20 ms 32288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 36308 KB Output is correct
2 Correct 20 ms 40200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 146 ms 157740 KB Output is correct
2 Correct 192 ms 196708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 234 ms 235908 KB Output is correct
2 Correct 287 ms 314188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 327 ms 353252 KB Output is correct
2 Correct 352 ms 392452 KB Output is correct