# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
984916 | normankr07 | Stove (JOI18_stove) | C++17 | 15 ms | 3304 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#define taskname ""
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifndef LOCAL
#define cerr \
if (0) \
cerr
#endif
const bool multitest = 0;
const int MAXN = 2e5;
ll t[MAXN];
void solve()
{
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++)
{
cin >> t[i];
}
// Goal, minimize total turned on time
// Active time = t[n] - t[1];
// Got k time -> find the most k diff time to turn off;
vector<ll> diff;
ll sum = t[n] - t[1] + 1;
for (int i = 2; i <= n; i++)
{
diff.push_back(t[i] - t[i - 1]);
}
sort(diff.begin(), diff.end());
while (k-- > 1 && diff.size())
{
sum -= (diff.back() - 1);
diff.pop_back();
}
cout << sum;
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
if (fopen(taskname ".inp", "r"))
{
freopen(taskname ".inp", "r", stdin);
freopen(taskname ".out", "w", stdout);
}
int tc = 1;
if (multitest)
cin >> tc;
while (tc--)
{
solve();
cout << '\n';
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |