Skip to content

Commit fe072a8

Browse files
committedNov 20, 2023
Tutorial: Algortihmic Grand Prix Added except Last
1 parent 96e9ae5 commit fe072a8

File tree

64 files changed

+753
-184
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+753
-184
lines changed
 
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include "bits/stdc++.h"
2+
3+
using i64 = long long;
4+
5+
void solve()
6+
{
7+
int a, b;
8+
std::cin >> a >> b;
9+
10+
int c = std::min(a % b, b - a % b);
11+
int k1 = (c - a) / b;
12+
int k2 = (-c - a) / b;
13+
14+
i64 A = a + 1LL * k1 * b;
15+
i64 B = a + 1LL * k2 * b;
16+
17+
if (A != B and std::abs(A) == std::abs(B))
18+
std::cout << "YES\n";
19+
else
20+
std::cout << "NO\n";
21+
}
22+
23+
int main()
24+
{
25+
int t;
26+
std::cin >> t;
27+
28+
while (t--)
29+
solve();
30+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include "bits/stdc++.h"
2+
3+
using i64 = long long;
4+
5+
void solve()
6+
{
7+
int n, k;
8+
std::cin >> n >> k;
9+
10+
std::vector<int> h(n);
11+
std::vector a(n, std::array<int, 2>());
12+
for (int i = 0; i < n; i++)
13+
std::cin >> h[i];
14+
15+
for (int i = 0; i < n; i++)
16+
{
17+
std::cin >> a[i][1];
18+
a[i][0] = h[i];
19+
}
20+
21+
std::sort(std::begin(a), std::end(a));
22+
std::multiset<std::pair<int, int>> m;
23+
24+
std::vector<int> ans;
25+
int cnt = 0;
26+
for (int i = 0, id = 0; i < n; i++)
27+
{
28+
while (id < n and a[id][0] <= k)
29+
{
30+
m.emplace(-a[id][1], a[id][0]);
31+
id++;
32+
}
33+
34+
if (m.empty())
35+
break;
36+
37+
cnt++;
38+
auto [energy_gain, height] = *std::begin(m);
39+
m.erase(std::begin(m));
40+
41+
k += -energy_gain;
42+
ans.emplace_back(k);
43+
}
44+
45+
std::cout << cnt << "\n";
46+
for (int i = 0; i < cnt; i++)
47+
std::cout << ans[i] << " ";
48+
std::cout << "\n";
49+
}
50+
51+
int main()
52+
{
53+
int t;
54+
std::cin >> t;
55+
56+
while (t--)
57+
solve();
58+
59+
return 0;
60+
}

0 commit comments

Comments
 (0)
Please sign in to comment.