-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy path1282C.cpp
executable file
·47 lines (40 loc) · 910 Bytes
/
1282C.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
// Problem Code: 1282C
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int petya_and_exam(int n, int T, int a, int b, vector<int>& d, vector<int>& t) {
int points, easy, s, rem;
vector< pair<int, int> > q(n);
points = easy = s = 0;
for (int i = 0; i < n; i++) {
q[i] = {t[i], d[i]};
easy += d[i] == 0;
}
q.push_back({T + 1, -1});
sort(q.begin(), q.end());
for (int i = 0; i <= n && s <= T; i++) {
if (s < q[i].first) {
rem = q[i].first - s - 1;
points = max(i + min(rem / a, easy), points);
}
s += (q[i].second) ? b : a;
easy -= q[i].second == 0;
}
return points;
}
int main() {
int m;
cin >> m;
while (m--) {
int n, T, a, b;
cin >> n >> T >> a >> b;
vector<int> d(n), t(n);
for (int i = 0; i < n; i++)
cin >> d[i];
for (int i = 0; i < n; i++)
cin >> t[i];
cout << petya_and_exam(n, T, a, b, d, t) << endl;
}
return 0;
}