이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
#define see(x) cout<<#x<<"="<<x<<"\n";
#define endl "\n"
using namespace std;
const int N = 1e5+5;
int n, k, t[N], pos[N];
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
/*
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
*/
cin >> n >> k;
vector <pair <int, int>> stop;
for (int i = 0; i < n; i ++) {
cin >> t[i];
}
for (int i = 0; i < n; i ++) {
if (i + 1 < n) {
stop.push_back({t[i+1] - t[i], i});
}
}
sort(stop.rbegin(), stop.rend());
for (int i = 0; i < k - 1; i ++) {
pos[stop[i].second] = 1;
}
int flag = 0, res = 0;
for (int i = 0; i < n; i ++) {
if (pos[i]) res ++;
if (i and pos[i-1]) continue;
res += t[i] - t[i-1];
}
cout << res << endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
stove.cpp: In function 'int32_t main()':
stove.cpp:39:9: warning: unused variable 'flag' [-Wunused-variable]
39 | int flag = 0, res = 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... |