답안 #958194

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
958194 2024-04-05T06:20:43 Z ddogurgi 택배 (KOI13_delivery) C++17
100 / 100
3 ms 860 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
#include <queue>

using namespace std;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int ans = 0;
    int truck_loaded = 0;
    int truck_loaded_dest[10001];
    int N, C, M, a, b, c;
    cin >> N >> C;
    cin >> M;
    vector<tuple<int, int, int>> v;
    priority_queue<int> pq;
    for(int i = 0; i < M; i++){
        cin >> a >> b >> c;
        v.push_back(make_tuple(a, b, c));
    }
    sort(v.begin(), v.end());
    for(int i = 0; i < M; i++){
        tie(a, b, c) = v[i];
        int cur_loaded = 0;
        if(i && (a != get<0>(v[i-1]))){
            for(int j = get<0>(v[i-1])+1; j <= a; j++){
                ans += truck_loaded_dest[j];
                truck_loaded -= truck_loaded_dest[j];
                truck_loaded_dest[j] = 0;
            }
        }
        if(truck_loaded+c <= C){
            if(!truck_loaded_dest[b])
                pq.push(b);
            truck_loaded += c;
            truck_loaded_dest[b] += c;
            continue;
        }
        if(truck_loaded+c > C && truck_loaded < C){
            if(!truck_loaded_dest[b])
                pq.push(b);
            truck_loaded_dest[b] += C-truck_loaded;
            cur_loaded = C-truck_loaded;
            truck_loaded = C;
        }
        if(truck_loaded == C){
            while(!pq.empty() && pq.top() > b && cur_loaded < c){
                int biggest = pq.top();
                if(truck_loaded_dest[biggest] <= c-cur_loaded){
                    if(!truck_loaded_dest[b])
                        pq.push(b);
                    truck_loaded_dest[b] += truck_loaded_dest[biggest];
                    cur_loaded += truck_loaded_dest[biggest];
                    truck_loaded_dest[biggest] = 0;
                    pq.pop();
                }
                else{
                    if(!truck_loaded_dest[b])
                        pq.push(b);
                    truck_loaded_dest[b] += c-cur_loaded;
                    truck_loaded_dest[biggest] -= c-cur_loaded;
                    cur_loaded = c;
                }
            }
        }
    }
    cout << ans+truck_loaded << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 492 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 3 ms 860 KB Output is correct
4 Correct 3 ms 860 KB Output is correct
5 Correct 3 ms 860 KB Output is correct