Submission #524353

# Submission time Handle Problem Language Result Execution time Memory
524353 2022-02-09T05:31:00 Z blue Akcija (COCI15_akcija) C++17
80 / 80
16 ms 2424 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

using ll = long long;
using vll = vector<ll>;

const ll INF = 1'000'000'000'000LL;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int N;
	cin >> N;

	vll C(1+N, 0);
	for(int i = 1; i <= N; i++) cin >> C[i];

	sort(C.begin(), C.end());

	vll dp(1+N, INF);
	dp[0] = 0;

	for(int i = 1; i <= N; i++)
	{
		dp[i] = dp[i-1] + C[i];

		if(i >= 3)
		{
			dp[i] = min(dp[i], dp[i-3] + C[i] + C[i-1]);
		}
	}
	cout << dp[N] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 12 ms 2244 KB Output is correct
7 Correct 8 ms 2252 KB Output is correct
8 Correct 11 ms 2280 KB Output is correct
9 Correct 16 ms 2424 KB Output is correct
10 Correct 16 ms 2412 KB Output is correct