Submission #298871

# Submission time Handle Problem Language Result Execution time Memory
298871 2020-09-14T08:50:32 Z shrek12357 Kas (COCI17_kas) C++14
100 / 100
240 ms 196472 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
using namespace std;

const int MAXV = 1e5+5;
#define MAXN 505

int main() {
	int dp[MAXN][MAXV];
	int best = 0;
	int n;
	cin >> n;
	vector<int> nums;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < MAXV; j++) {
			dp[i][j] = INT_MIN;
		}
	}
	dp[0][0] = 0;
	for (int i = 0; i < n; i++) {
		int temp;
		cin >> temp;
		nums.push_back(temp);
		sum += temp;
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < MAXV; j++) {
			dp[i][j] = max(dp[i - 1][j], max(dp[i - 1][j + nums[i - 1]], dp[i - 1][abs(j - nums[i - 1])]) + nums[i - 1]);
		}
		best = max(best, dp[i][0]);
	}
	cout << best/2 + sum-best << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4608 KB Output is correct
2 Correct 6 ms 4608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 4608 KB Output is correct
2 Correct 6 ms 4640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4608 KB Output is correct
2 Correct 8 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5376 KB Output is correct
2 Correct 9 ms 5760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5760 KB Output is correct
2 Correct 7 ms 5864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 14464 KB Output is correct
2 Correct 21 ms 16376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 18304 KB Output is correct
2 Correct 28 ms 20216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 100 ms 79048 KB Output is correct
2 Correct 125 ms 98584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 156 ms 118268 KB Output is correct
2 Correct 194 ms 157304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 221 ms 176888 KB Output is correct
2 Correct 240 ms 196472 KB Output is correct