이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define F first
#define S second
#define LL long long
#define rep(i, x) for(auto &i : (x))
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define left(x) ((x)<<1)
#define right(x) ((x)>>1)
#define LSOne(x) (x & -(x))
using namespace std;
using T = pair<pair<int, int>, int>;
const int SZ = 2e5 + 1;
const LL MOD = 1e9 + 7;
const LL INF = 1e18 + 1;
LL bp (LL b, LL e, LL m = MOD) {
if ( e == 0 ) return 1;
LL T = bp(b, e / 2);
T *= T; T %= m;
if ( e & 1 ) T *= b;
return T %= m;
}
LL nv_i (LL a) { return bp(a, MOD - 2); };
LL gcd (LL a, LL b) { return (b == 0 ? a : gcd(b, a % b)); }
LL lcm(LL a, LL b) { return (a * (b / gcd(a, b))); }
LL ceil (LL a, LL b) { return ((a + b - 1) / b); }
void solve() {
int n, k;
cin >> n >> k;
vector<int> V(n);
rep(i, V) cin >> i;
priority_queue<int, vector<int>, greater<int>> PQ;
for(int i = 0; i < n - 1; i ++) {
PQ.push(V[i + 1] + 1 - V[i]);
}
if(k == n) {
cout << k;
return;
}
if(k == 1) {
cout << V[n - 1];
return;
}
int cnt = 0;
while(k--) {
cnt += PQ.top();
PQ.pop();
if(PQ.size() == k) {
cnt += k;
break;
}
}
cout << cnt;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
stove.cpp: In function 'void solve()':
stove.cpp:62:18: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
62 | if(PQ.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... |