답안 #1017516

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017516 2024-07-09T08:36:49 Z vjudge1 Stove (JOI18_stove) C++17
0 / 100
0 ms 348 KB
#include <iostream>
#include <vector>
#include <algorithm>
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());
    int matches_used = 0;
    int current_time = 0;
    bool heater_on = false;
    int total_heating_time = 0;
    for (const auto& event : events) {
        int event_time = event.time;
        bool is_start = event.is_start;
        if (is_start) {
            if (!heater_on && matches_used < K) {
                heater_on = true;
                matches_used++;
                total_heating_time += (event_time - current_time);
            }
        } else { 
            if (heater_on) {
                heater_on = false;
                total_heating_time += (event_time - current_time);
            }
        }
        current_time = event_time;
    }
    cout << total_heating_time << endl;
    return 0;
}
# 결과 실행 시간 메모리 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 -