-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.cpp
41 lines (36 loc) · 888 Bytes
/
main.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
// Author : Qi Zhang
// Date : 2019-03-30
#include <bits/stdc++.h>
using namespace std;
vector<int> tp(1e5+1, 0);
struct people{
int arr, wa;
people(int a, int b): arr(a), wa(b) {}
};
int main(){
int n, k, q;
cin >> n >> k >> q;
for(int i = 0; i < q; i++) {
int x, y;
cin >> x >> y;
tp[x] += y;
}
int last;
cin >> last;
tp[last]++;
int i = 1;
queue<people> wash, wait;
for(;; i++){
//cout << i << endl;
while(!wash.empty() && i - wash.front().wa == k) wash.pop();
int num = tp[i];
while(i <= last && num--) wait.push(people(i, -1));
while(wash.size() < n && !wait.empty()) {
wait.front().wa = i;
wash.push(wait.front());
wait.pop();
}
if(i > last && wash.empty() && wait.empty()) break;
}
cout << i << endl;
}