Submission #1017529

# Submission time Handle Problem Language Result Execution time Memory
1017529 2024-07-09T08:40:18 Z vjudge1 Stove (JOI18_stove) C++17
0 / 100
0 ms 348 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
struct Event {
    int time;
    bool is_start;
    Event(int t, bool start) : time(t), is_start(start) {}
    bool operator<(const Event& other) const {
        if (time == other.time) {
            return !is_start < !other.is_start;
        }
        return time < other.time;
    }
};
int main() {
    int N, K;
    cin >> N >> K;
    vector<Event> events;
    for (int i = 0; i < N; ++i) {
        int T;
        cin >> T;
        events.emplace_back(T, true);    
        events.emplace_back(T + 1, false); 
    }
    sort(events.begin(), events.end());
    priority_queue<int, vector<int>, greater<int>> active_guests; 
    int matches_used = 0;
    long long total_heating_time = 0;
    int current_time = 0;
    for (const auto& event : events) {
        int event_time = event.time;
        bool is_start = event.is_start;
        if (is_start) {
            if (active_guests.empty() && matches_used < K) {
                matches_used++;
                active_guests.push(event_time + 1); 
                total_heating_time += (event_time + 1 - current_time);
            } else {
                active_guests.push(event_time + 1);
            }
        } else { 
            active_guests.pop();
            if (active_guests.empty()) {
                total_heating_time += (event_time - current_time);
            }
        }
        current_time = event_time;
    }
    cout << total_heating_time << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -