제출 #783925

#제출 시각아이디문제언어결과실행 시간메모리
783925BoasStove (JOI18_stove)C++17
100 / 100
37 ms896 KiB
#include <bits/stdc++.h>
using namespace std;
#define loop(x) for (int i = 0; i < x; i++)
 
int main()
{
    int N, K;
    cin >> N >> K;
    priority_queue<int> gaps;
    int prevT = -1;
    int matchesUsed = 0;
    int burnTime = N;
    loop(N)
    {
        int t;
        cin >> t;
        if (prevT == -1 || t - prevT > 1)
        {
            matchesUsed++;
            if (prevT != -1)
            {
                gaps.push(prevT - t + 1); // -1 * gapSize
            }
        }
        prevT = t;
    }
    while (matchesUsed > K)
    {
        int g = -gaps.top();
        gaps.pop();
        matchesUsed--;
        burnTime += g;
    }
    cout << burnTime << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...