# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1109226 | codinion | Stove (JOI18_stove) | C++14 | 45 ms | 3792 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// https://oj.uz/problem/view/JOI18_stove
#include <iostream>
#include <algorithm>
#include <vector>
typedef long long ll;
using namespace std;
int main() {
int N,K;
cin>>N;
cin>>K;
ll* gg = new ll[N];
for(int i=0;i<N;i++) {
cin>>gg[i];
}
sort(gg, gg+N);
vector<ll> active;
vector<ll> inactive;
ll totact = 0;
ll curract = 1;
for(int i = 1;i<N; i++) {
if(gg[i] - gg[i-1] == 1) {
curract++;
} else {
inactive.push_back(gg[i]-gg[i-1]-1);
active.push_back(curract);
totact+=curract;
curract = 1;
}
}
totact+=curract;
active.push_back(curract);
if(active.size() > K)
{
ll diff = active.size()-K;
sort(inactive.begin(), inactive.end());
for(ll i = 0;i<diff;i++)
totact += inactive[i];
}
cout<<totact<<endl;
}
컴파일 시 표준 에러 (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... |