이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define pb push_back
#define endl '\n'
using namespace std;
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;
int t[N];
bool e(pair<int,pair<int,int>> a, pair<int,pair<int,int>> b) {
return (a.S.F < b.S.S);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, k;
cin >> n >> k;
vector<pair<int, pair<int, int>>> v;
for (int i = 0; i < n; ++i) {
cin >> t[i];
if (i) v.pb({t[i] - t[i - 1], { i-1, i}});
}
sort(v.rbegin(), v.rend());
while(v.size() >= k)
v.erase(v.begin() + k);
sort(v.begin(), v.end(), e);
ll sum = 0;
int l = 0;
for ( auto i: v) {
//cout << i.S.F << " " << i.S.S << endl;
sum += (t[i.S.F] - t[l] + 1) * 1LL;
l = i.S.S;
}
sum += (t[n-1] - t[l] + 1) * 1LL;
cout << sum << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
stove.cpp: In function 'int main()':
stove.cpp:30:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(v.size() >= k)
~~~~~~~~~^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |