Submission #932676

#TimeUsernameProblemLanguageResultExecution timeMemory
932676jotnStove (JOI18_stove)C++17
0 / 100
0 ms348 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...