#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 1ll<<60
#define rep(i,a,b) for (ll i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
#define endl "\n"
void inc(ll &a,ll b) {a=(a+b)%mod;}
void dec(ll &a,ll b) {a=(a-b+mod)%mod;}
int lowbit(ll x) {return x&(-x);}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
//freopen("i.txt","r",stdin);
ll N, K;
cin >> N >> K;
vector<pair<ll, ll>> list;
ll arrival;
for(ll i = 0; i < N; ++i) {
cin >> arrival;
list.push_back({arrival, arrival+1});
}
sort(ALL(list));
int stove_on = 0;
int total_operating_time = 0;
int stove_turn_on_count = 0;
for (int i = 0; i < N; ++i) {
int guest_arrival = list[i].first;
int guest_departure = list[i].second;
total_operating_time += max(0, guest_arrival - stove_on);
stove_on = max(stove_on, guest_departure);
if (stove_turn_on_count < K) {
total_operating_time += 1; // Turn on stove
stove_turn_on_count++;
}
}
cout << total_operating_time;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
- |