CSES - Datatähti 2021 loppu - Results
Submission details
Task:Koodarit
Sender:hltk
Submission time:2021-01-23 18:48:31 +0200
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

In file included from /usr/include/features.h:424:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:533,
                 from /usr/include/c++/7/utility:68,
                 from /usr/include/c++/7/algorithm:60,
                 from input/code.cpp:3:
/usr/include/x86_64-linux-gnu/bits/stdlib-float.h: In function 'double atof(const char*)':
/usr/include/x86_64-linux-gnu/bits/stdlib-float.h:25:1: error: SSE register return with SSE disabled
 __NTH (atof (const char *__nptr))
 ^

Code

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("arch=skylake,tune=native,sse4")
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
constexpr ll INF = 1e18;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n, k;
	cin >> n >> k;

	vector<int> a(n);
	for (auto& x : a) cin >> x;

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

	vector<int> na;
	for (int i = 0; i < n; ++i) {
		if (i + 1 < n && a[i] == a[i + 1]) {
			k--;
			i++;
		} else na.push_back(a[i]);
	}

	if (k <= 0) {
		cout << 0 << '\n';
		return 0;
	}

	n = (int)na.size();

	vector<vector<ll>> dp(3, vector<ll>(k + 1, INF));
	dp[1][0] = 0;

	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j <= k; ++j) {
			dp[2][j] = min(dp[2][j], dp[1][j]);
		}
		if (i >= 2) {
			ll x = na[i - 1] - na[i - 2];
			for (int j = 1; j <= k; ++j) {
				dp[2][j] = min(dp[2][j], dp[0][j - 1] + x);
			}
		}
		swap(dp[0], dp[1]);
		swap(dp[1], dp[2]);
	}
	cout << min({dp[0][k], dp[1][k], dp[2][k]}) << '\n';
}