forked from encrypted-def/basic-algo-lecture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
8980.cpp
37 lines (35 loc) · 803 Bytes
/
8980.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Authored by : heheHwang
// Co-authored by : -
// http://boj.kr/123db07eeef44a39b14ceb22d7f77f2b
#include <bits/stdc++.h>
using namespace std;
int N, C, M, ans;
int truck[2002];
vector<tuple<int, int, int>> orders;
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N >> C >> M;
int f, t, b;
for (int i = 0; i < M; i++) {
cin >> f >> t >> b;
orders.push_back({t, f, b});
}
sort(orders.begin(), orders.end());
for (auto v : orders) {
tie(t, f, b) = v;
bool loadable = true;
for (int i = f; i < t; i++) {
b = min(b, C - truck[i]);
if (!b) {
loadable = false;
break;
}
}
if (loadable) {
ans += b;
for (int i = f; i < t; i++) truck[i] += b;
}
}
cout << ans;
}