#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |