-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path202303-2.cpp
39 lines (39 loc) · 870 Bytes
/
202303-2.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
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int n, m, k;
int t[N], c[N];
int main()
{
cin >> n >> m >> k;
for (int i = 0; i < n; i++) {
cin >> t[i] >> c[i];
}
auto f = [&](const int& i1, const int& i2) {
return t[i1] < t[i2];
};
priority_queue<int, vector<int>, decltype(f)> pq(f);
for (int i = 0; i < n; i++) {
pq.push(i);
}
int T = t[pq.top()], C = 0;
while (true) {
while (!pq.empty() && t[pq.top()] == T) {
C += c[pq.top()];
pq.pop();
}
if (pq.empty()) {
cout << max(k, T - m / C);
break;
}
int ti = t[pq.top()];
if (C * (T - ti) < m) {
m -= C * (T - ti);
} else {
cout << (T - m / C);
break;
}
T = ti;
}
return 0;
}