-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path15804.cpp
65 lines (61 loc) · 1.32 KB
/
15804.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//
// Created by kdongha on 2020/01/21.
//
#include <bits/stdc++.h>
int n, m, ans;
struct Bus {
int t;
int p;
};
Bus bus[101];
struct Stop {
int t;
int order;
};
std::deque<Stop> q;
void solve() {
std::cin >> n >> m;
for (int i = 1; i <= m; i++) {
std::cin >> bus[i].t >> bus[i].p;
}
int idx = 1;
int t = 0;
while (++t) {
while (!q.empty()) {
if (q.front().t <= t) {
q.pop_front();
} else {
break;
}
}
while (q.empty() || q.back().order < n) {
if (bus[idx].t <= t) {
if (idx == m) {
if (q.empty()) {
ans = 1;
} else {
ans = q.back().order + 1;
}
t=-1;
break;
}
if (q.empty()) {
q.push_back({t + bus[idx].p, 1});
} else {
q.push_back({t + bus[idx].p, q.back().order + 1});
}
idx++;
} else {
break;
}
}
}
std::cout << ans;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
solve();
return 0;
}