# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
875623 | raul2008487 | Stove (JOI18_stove) | C++17 | 15 ms | 3352 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define eb emplace_back
#define vl vector<ll>
#define fi first
#define se second
#define in insert
#define mpr make_pair
#define lg(x) __lg(x)
#define bpc(x) __builtin_popcount(x)
#define all(v) v.begin(), v.end()
#define endl "\n"
using namespace std;
const int sz = 2e5+5; /// size is changed
const int mod = 1e9+7;
const ll inf = 1000000000;
ll a[sz];
void solve(){
ll n, k, i, j;
cin>>n>>k;
vl v(n), dis;
for(i=0;i<n;i++){
cin>>v[i];
}
ll last = v[0], cnt = 1, ans = n;
for(i=1;i<n;i++){
if((v[i]-1) != last){
dis.pb(v[i]-1-last);
cnt++;
}
last = v[i];
}
//cout <<endl<< cnt << endl;
if(k >= cnt){
cout << n << endl;
return ;
}
sort(all(dis));
cnt -= k;
for(i=0;i<cnt;i++){
ans += dis[i];
}
cout << ans << endl;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//precomp();
ll tst=1;
//cin>>tst;
while(tst--){
solve();
}
}
/*
10 1
1
2
5
6
8
11
13
15
16
20
*/
컴파일 시 표준 에러 (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... |