-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA_Helmets_in_Night_Light.cpp
More file actions
108 lines (85 loc) · 1.91 KB
/
A_Helmets_in_Night_Light.cpp
File metadata and controls
108 lines (85 loc) · 1.91 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fast_io \
ios::sync_with_stdio(false); \
cin.tie(nullptr);
void query()
{
int n, p;
cin >> n >> p;
multimap<int, int> mp;
vector<int> va(n), vb(n);
for (int i = 0; i < n; ++i)
cin >> va[i];
for (int i = 0; i < n; ++i)
cin >> vb[i];
for (int i = 0; i < n; ++i)
{
mp.emplace(vb[i], va[i]);
}
int c = p, r = n - 1;
for (const auto &[b, a] : mp)
{
if (b > p || r <= 0)
break;
int x = min(r, a);
c += (b * x);
r -= x;
}
if (r > 0)
{
c += r * p;
}
cout << c << endl;
}
signed main()
{
fast_io;
int t;
cin >> t;
while (t--)
{
query();
}
return 0;
}
// #include <bits/stdc++.h>
// using namespace std;
// #define int long long
// #define fast_io ios::sync_with_stdio(false); cin.tie(nullptr);
// void query() {
// int n, p;
// cin >> n >> p;
// vector<int> va(n), vb(n);
// for (int i = 0; i < n; i++) cin >> va[i];
// for (int i = 0; i < n; i++) cin >> vb[i];
// vector<pair<int, int>> pairs;
// for (int i = 0; i < n; i++) {
// pairs.push_back({vb[i], va[i]});
// }
// sort(pairs.begin(), pairs.end());
// int c = p;
// int r = n - 1;
// for (auto& edge : pairs) {
// int cost = edge.first;
// int limit = edge.second;
// if (cost >= p || r <= 0) break;
// int d = min(r, limit);
// c += (d * cost);
// r -= d;
// }
// if (r > 0) {
// c += (r * p);
// }
// cout << c << endl;
// }
// signed main() {
// fast_io;
// int t;
// cin >> t;
// while (t--) {
// query();
// }
// return 0;
// }