Submission #289600

# Submission time Handle Problem Language Result Execution time Memory
289600 2020-09-02T18:53:06 Z FlashGamezzz Kas (COCI17_kas) C++14
100 / 100
224 ms 2048 KB
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>

using namespace std;

long dp[100001], temp[100001];
long sum, notes[500];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> notes[i];
		sum += notes[i];
	}
	for (long j = 0; j < 100001; j++){
		dp[j] = 100001;
	}
	dp[0] = 0;
	for (int i = 0; i < n; i++){
		for (long j = 0; j < 100001; j++){
			temp[j] = 100001;
		}
		for (long j = 0; j < 100001; j++){
			temp[j] = min(temp[j], dp[j]+notes[i]);
			temp[abs(j-notes[i])] = min(temp[abs(j-notes[i])], dp[j]);
			temp[j+notes[i]] = min(temp[j+notes[i]], dp[j]);
		}
		for (long j = 0; j < 100001; j++){
			dp[j] = temp[j];
		}
	}
	cout << sum-(sum-dp[0])/2 << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1920 KB Output is correct
2 Correct 7 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1920 KB Output is correct
2 Correct 5 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1920 KB Output is correct
2 Correct 8 ms 1952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1920 KB Output is correct
2 Correct 8 ms 1960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1920 KB Output is correct
2 Correct 7 ms 2048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1920 KB Output is correct
2 Correct 19 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 1920 KB Output is correct
2 Correct 23 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 1920 KB Output is correct
2 Correct 108 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 133 ms 2040 KB Output is correct
2 Correct 174 ms 1944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 192 ms 2040 KB Output is correct
2 Correct 224 ms 2040 KB Output is correct