이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
int main() {
int N,K;
cin>>N>>K;
vector<int> arrivals(N);
for(int i=0; i<N; ++i) {
cin>>arrivals[i];
}
sort(arrivals.begin(),arrivals.end());
priority_queue<int,vector<int>,greater<int>> pq;
int current_matches=0;
long long total_time = 0;
for(int i=0; i<N; ++i) {
int guest_arrival=arrivals[i];
if(current_matches<K) {
current_matches++;
total_time+=1;
pq.push(guest_arrival+1);
} else {
int earliest_leave_time=pq.top();
if(earliest_leave_time<guest_arrival) {
pq.pop();
total_time+=earliest_leave_time-guest_arrival;
pq.push(guest_arrival+1);
}
}
}
cout<<total_time<<endl;
return 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... |