이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair <LL, int> PLLI;
constexpr int NMAX = 1e5 + 5;
constexpr LL CPF = 1e6;
int N, K;
int T[NMAX];
PLLI dp[NMAX];
void Read () {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N >> K;
for (int i = 1; i <= N; ++ i )
cin >> T[i];
}
PLLI Check (LL costChange) {
dp[1] = {CPF + costChange, 1};
for (int i = 2; i <= N; ++ i ) {
PLLI x, y;
x = {dp[i-1].first + 1LL * ((T[i]+1) - (T[i-1]+1)) * CPF, dp[i-1].second};
y = {dp[i-1].first + 1LL * costChange + 1LL * CPF, dp[i-1].second + 1};
dp[i] = min(x, y);
}
return dp[N];
}
void Solve () {
LL st = 0, dr = 1LL * 1e12;
while (st <= dr) {
LL mij = (st + dr) / 2;
PLLI ans = Check(mij);
if (ans.second == K) {
cout << (ans.first - 1LL * ans.second * mij) / CPF << '\n';
return;
}
if (ans.second > K) {
st = mij + 1;
}
else dr = mij - 1;
}
PLLI ans = Check(st);
cout << (ans.first - 1LL * K * st) / CPF << '\n';
}
void SolveNotAlien () {
multiset <int> MS;
for (int i = 2; i <= N; ++ i ) {
MS.insert(T[i] - (T[i-1]+1));
}
int ans = N;
for (int i = 1; i <= N-K; ++ i ) {
int value = *(MS.begin());
MS.erase(MS.begin());
ans += value;
}
cout << ans << '\n';
}
int main () {
Read();
SolveNotAlien();
//Solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |