이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |