A. Diagonals
Problem Statement
Vitaly503 is given a checkered board with a side of n n n and k k k chips. He realized that all these k k k chips need to be placed on the cells of the board (no more than one chip can be placed on a single cell).
Let’s denote the cell in the i i i-th row and j j j-th column as ( i , j ) (i ,j) (i,j). A diagonal is the set of cells for which the value i + j i + j i+j is the same. For example, cells ( 3 , 1 ) (3, 1) (3,1), ( 2 , 2 ) (2, 2) (2,2), and ( 1 , 3 ) (1, 3) (1,3) lie on the same diagonal, but ( 1 , 2 ) (1, 2) (1,2) and ( 2 , 3 ) (2, 3) (2,3) do not. A diagonal is called occupied if it contains at least one chip.
Determine what is the minimum possible number of occupied diagonals among all placements of k k k chips.
Input
Each test consists of several sets of input data. The first line contains a single integer t t t ( 1 ≤ t ≤ 500 1 \le t \le 500 1≤t≤500) — the number of sets of input data. Then follow the descriptions of the sets of input data.
The only line of each set of input data contains two integers n n n, k k k ( 1 ≤ n ≤ 100 , 0 ≤ k ≤ n 2 1 \le n \le 100, 0 \le k \le n^2 1≤n≤100,0≤k≤n2) — the side of the checkered board and the number of available chips, respectively.
Output
For each set of input data, output a single integer — the minimum number of occupied diagonals with at least one chip that he can get after placing all k k k chips.
Example
input |
---|
7 |
1 0 |
2 2 |
2 3 |
2 4 |
10 50 |
100 239 |
3 9 |
output |
---|
0 |
1 |
2 |
3 |
6 |
3 |
5 |
Note
In the first test case, there are no chips, so 0 diagonals will be occupied. In the second test case, both chips can be placed on diagonal ( 2 , 1 ) , ( 1 , 2 ) (2, 1), (1, 2) (2,1),(1,2), so the answer is 1. In the third test case, 3 chips can’t be placed on one diagonal, but placing them on ( 1 , 2 ) , ( 2 , 1 ) , ( 1 , 1 ) (1, 2), (2, 1), (1, 1) (1,2),(2,1),(1,1) makes 2 diagonals occupied. In the 7th test case, chips will occupy all 5 diagonals in any valid placing.
Solution
具体见文后视频。
Code
#include <bits/stdc++.h>
#define fi first
#define se second
#define int long long
using namespace std;
typedef pair<int, int> PII;
typedef long long LL;
void solve() {
int n, k;
cin >> n >> k;
if (!k) cout << 0 << endl;
else if (k <= n) cout << 1 << endl;
else {
k -= n;
int res = 1;
for (int i = n - 1; i >= 1; i --) {
if (k > i) k -= i, res ++;
else { res ++; break; }
if (k > i) k -= i, res ++;
else { res ++; break; }
}
cout << res << endl;
}
}
signed main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int dt;
cin >> dt;
while (dt --)
solve();
return 0;
}
B1. Bouquet (Easy Version)
Problem Statement
This is the easy version of the problem. The only difference is that in this version, the flowers are specified by enumeration.
A girl is preparing for her birthday and wants to buy the most beautiful bouquet. There are a total of n n n flowers in the store, each of which is characterized by the number of petals, and a flower with k k k petals costs k k k coins. The girl has decided that the difference in the number of petals between any two flowers she will use in her bouquet should not exceed one. At the same time, the girl wants to assemble a bouquet with the maximum possible number of petals. Unfortunately, she only has m m m coins, and she cannot spend more. What is the maximum total number of petals she can assemble in the bouquet?
Input
Each test consists of several test cases. The first line contains a single integer t t t ( 1 ≤ t ≤ 10 000 1 \le t \le 10\,000 1≤t≤10000) — the number of test cases. This is followed by descriptions of the test cases.
The first line of each test case contains two integers n n n, m m m ( 1 ≤ n ≤ 2 ⋅ 1 0 5 , 1 ≤ m ≤ 1 0 18 1 \le n \le 2 \cdot 10^5, 1 \le m \le 10^{18} 1≤n≤2⋅105,1≤m≤1018) — the number of flowers in the store and the number of coins the girl possesses, respectively. The second line of each test case contains n n n integers a 1 , a 2 , … , a n a_1, a_2, \ldots, a_n a1,a2,…,an ( 1 ≤ a i ≤ 1 0 9 1 \le a_i \le 10^9 1≤ai≤109), where a i a_i ai is the number of petals of the i i i-th flower in the store.
The sum of n n n over all test cases does not exceed 2 ⋅ 10 5 2 \cdot {10}^5 2⋅105.## Output
For each testcase, if it’s possible to make a = [ 1 ] a=[1] a=[1], print YES. Otherwise, print NO. You can output the answer in any case (upper or lower). For example, the strings yEs, yes, Yes, and YES will be recognized as positive responses.
Output
For each test case, output a single integer — the maximum possible number of petals in the bouquet that the girl can assemble while meeting all the conditions listed above.
Example
input |
---|
5 |
5 10 |
1 1 2 2 3 |
8 20 |
4 2 7 5 6 1 1 1 |
8 100000 |
239 30 610 122 24 40 8 2 |
11 13 |
2 4 11 1 1 2 3 5 4 3 2 |
8 1033 |
206 206 206 207 207 207 207 1000 |
output |
---|
7 |
13 |
610 |
13 |
1033 |
Note
In the first test case, you can assemble a bouquet with ( 1 , 1 , 2 , 2 ) , ( 2 , 2 , 3 ) , ( 1 , 1 ) , ( 2 , 2 ) (1, 1, 2, 2), (2, 2, 3), (1, 1), (2, 2) (1,1,2,2),(2,2,3),(1,1),(2,2). The maximum over all valid bouquets not greater than 10 10 10 is 7 7 7 for ( 2 , 2 , 3 ) (2, 2, 3) (2,2,3). In the third test case, you can assemble a bouquet with only one flower of any type, so the answer is 610 610 610. In the fourth test case, you can assemble a bouquet with ( 4 , 4 , 5 ) (4, 4, 5) (4,4,5), which gives you 13 13 13 petals, and it is the maximum amount of petals that the girl can buy.
Solution
具体见文后视频。
Code
#include <bits/stdc++.h>
#define fi first
#define se second
#define int long long
using namespace std;
typedef pair<int, int> PII;
typedef long long LL;
void solve() {
int n, m;
cin >> n >> m;
std::vector<int> a(n + 1, 0), b(n + 1, 0);
for (int i = 1; i <= n; i ++) cin >> a[i];
sort(a.begin() + 1, a.end());
for (int i = 1; i <= n; i ++) b[i] = b[i - 1] + a[i];
int ans = 0;
for (int i = 1; i <= n; i ++) {
int j = i, pos = 0;
while (j < n && a[j + 1] <= a[i] + 1) {
if (a[j + 1] == a[i] + 1 && !pos) pos = j + 1;
j ++;
}
// i ~ j
for (int k = i; k <= j; k ++) {
int l = k, r = j, res = -1;
while (l <= r) {
int mid = l + r >> 1;
if (b[mid] - b[k - 1] <= m) l = mid + 1, res = mid;
else r = mid - 1;
}
if (~res) ans = max(ans, b[res] - b[k - 1]);
}
if (pos) i = pos - 1;
else i = j;
}
cout << ans << endl;
}
signed main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int dt;
cin >> dt;
while (dt --)
solve();
return 0;
}
B2. Bouquet (Hard Version)
Problem Statement
This is the hard version of the problem. The only difference is that in this version, instead of listing the number of petals for each flower, the number of petals and the quantity of flowers in the store is set for all types of flowers.
A girl is preparing for her birthday and wants to buy the most beautiful bouquet. There are a total of n n n different types of flowers in the store, each of which is characterized by the number of petals and the quantity of this type of flower. A flower with k k k petals costs k k k coins. The girl has decided that the difference in the number of petals between any two flowers she will use to decorate her cake should not exceed one. At the same time, the girl wants to assemble a bouquet with the maximum possible number of petals. Unfortunately, she only has m m m coins, and she cannot spend more. What is the maximum total number of petals she can assemble in the bouquet?
Input
Each test consists of several test cases. The first line contains a single integer t t t ( 1 ≤ t ≤ 10 000 1 \le t \le 10\,000 1≤t≤10000) — the number of test cases. This is followed by descriptions of the test cases.
The first line of each test case contains two integers n n n, m m m ( 1 ≤ n ≤ 2 ⋅ 1 0 5 , 1 ≤ m ≤ 1 0 18 1 \le n \le 2 \cdot 10^5, 1 \le m \le 10^{18} 1≤n≤2⋅105,1≤m≤1018) — the number of types of flowers in the store and the number of coins the girl possesses, respectively. The second line of each test case contains n n n different integers a 1 , a 2 , … , a n a_1, a_2, \ldots, a_n a1,a2,…,an ( 1 ≤ a i ≤ 1 0 9 1 \le a_i \le 10^9 1≤ai≤109), where a i a_i ai is the number of petals of the i i i-th flower type in the store (for different indexes i ≠ j i \neq j i=j, it must be a i ≠ a j a_i \neq a_j ai=aj). The third line of each test case contains n n n integers c 1 , c 2 , … , c n c_1, c_2, \ldots, c_n c1,c2,…,cn ( 1 ≤ c i ≤ 1 0 9 1 \le c_i \le 10^9 1≤ci≤109), where c i c_i ci is the quantity of the i i i-th flower type in the store.
The sum of n n n over all test cases does not exceed 2 ⋅ 10 5 2 \cdot {10}^5 2⋅105.
Output
For each test case, print one integer — the maximum possible number of petals in a bouquet that a girl can collect, observing all the conditions listed above.
Example
input |
---|
7 |
3 10 |
1 2 3 |
2 2 1 |
3 1033 |
206 207 1000 |
3 4 1 |
6 20 |
4 2 7 5 6 1 |
1 2 1 3 1 7 |
8 100000 |
239 30 610 122 24 40 8 2 |
12 13123 112 1456 124 100 123 10982 |
6 13 |
2 4 11 1 3 5 |
2 2 1 2 2 1 |
8 10330 |
206 210 200 201 198 199 222 1000 |
9 10 11 12 13 14 15 16 |
2 10000000000 |
11 12 |
87312315 753297050 |
output |
---|
7 |
1033 |
19 |
99990 |
13 |
10000 |
9999999999 |
Note
In the first test case, some valid bouquets are ( 1 , 1 , 2 , 2 ) , ( 2 , 2 , 3 ) , ( 1 , 1 ) , ( 2 , 2 ) (1, 1, 2, 2), (2, 2, 3), (1, 1), (2, 2) (1,1,2,2),(2,2,3),(1,1),(2,2). The maximum over all valid bouquets not greater than 10 10 10 is 7 7 7 for ( 2 , 2 , 3 ) (2, 2, 3) (2,2,3). In the second test case, you can assemble a valid bouquet with ( 206 , 206 , 207 , 207 , 207 ) (206, 206, 207, 207, 207) (206,206,207,207,207) with a sum of 1033 1033 1033, which is the maximum number of petals the girl can buy. In the third test case, you can assemble a valid bouquet with ( 5 , 5 , 5 , 4 ) (5, 5, 5, 4) (5,5,5,4) with a sum of 19 19 19. It can be seen that no valid bouquet can have 20 20 20 petals.
Solution
具体见文后视频。
Code
#include <bits/stdc++.h>
#define fi first
#define se second
#define int long long
using namespace std;
typedef pair<int, int> PII;
typedef long long LL;
void solve() {
int n, m;
cin >> n >> m;
std::vector<PII> a(n);
for (int i = 0; i < n; i ++) cin >> a[i].fi;
for (int i = 0; i < n; i ++) cin >> a[i].se;
sort(a.begin(), a.end());
int res = min(m / a[n - 1].fi, a[n - 1].se) * a[n - 1].fi;
for (int i = 0; i < n - 1; i ++) {
if (a[i + 1].fi > a[i].fi + 1) { res = max(res, min(m / a[i].fi, a[i].se) * a[i].fi); continue;}
int c1 = min(a[i].se, m / a[i].fi), c2 = min(a[i + 1].se, (m - c1 * a[i].fi) / a[i + 1].fi);
int add = min({a[i + 1].se - c2, c1, m - c1 * a[i].fi - c2 * a[i + 1].fi});
res = max(res, c1 * a[i].fi + c2 * a[i + 1].fi + add);
}
cout << res << endl;
}
signed main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int dt;
cin >> dt;
while (dt --)
solve();
return 0;
}
C. Squaring
Problem Statement
ikrpprpp found an array a a a consisting of integers. He likes justice, so he wants to make a a a fair — that is, make it non-decreasing. To do that, he can perform an act of justice on an index 1 ≤ i ≤ n 1 \le i \le n 1≤i≤n of the array, which will replace a i a_i ai with a i 2 a_i ^ 2 ai2 (the element at position i i i with its square). For example, if a = [ 2 , 4 , 3 , 3 , 5 , 3 ] a = [2,4,3,3,5,3] a=[2,4,3,3,5,3] and ikrpprpp chooses to perform an act of justice on i = 4 i = 4 i=4, a a a becomes [ 2 , 4 , 3 , 9 , 5 , 3 ] [2,4,3,9,5,3] [2,4,3,9,5,3].
What is the minimum number of acts of justice needed to make the array non-decreasing?
Input
First line contains an integer t t t ( 1 ≤ t ≤ 1000 1 \le t \le 1000 1≤t≤1000) — the number of test cases. It is followed by the description of test cases.
For each test case, the first line contains an integer n n n — size of the array a a a. The second line contains n n n ( 1 ≤ n ≤ 2 ⋅ 1 0 5 1 \le n \le 2 \cdot 10 ^5 1≤n≤2⋅105) integers a 1 , a 2 , … , a n a_1, a_2,\ldots, a_n a1,a2,…,an ( 1 ≤ a i ≤ 1 0 6 1 \le a_i \le 10 ^ 6 1≤ai≤106).
The sum of n n n over all test cases does not exceed 2 ⋅ 10 5 2 \cdot {10}^5 2⋅105.
Output
For each testcase, print an integer — minimum number of acts of justice required to make the array a a a non-decreasing. If it is impossible to do that, print − 1 -1 −1.
Example
input |
---|
7 |
3 |
1 2 3 |
2 |
3 2 |
3 |
3 1 5 |
4 |
1 1 2 3 |
3 |
4 3 2 |
9 |
16 2 4 2 256 2 4 2 8 |
11 |
10010 10009 10008 10007 10006 10005 10004 10003 10002 10001 10000 |
output |
---|
0 |
1 |
-1 |
0 |
3 |
15 |
55 |
Note
In the first test case, there’s no need to perform acts of justice. The array is fair on its own!
In the third test case, it can be proven that the array cannot become non-decreasing.
In the fifth test case, ikrpprppp can perform an act of justice on index 3, then an act of justice on index 2, and finally yet another act of justice on index 3. After that, a a a will become [ 4 , 9 , 16 ] [4, 9, 16] [4,9,16].
Solution
具体见文后视频。
Code
#include <bits/stdc++.h>
#define fi first
#define se second
#define int long long
using namespace std;
typedef pair<int, int> PII;
typedef long long LL;
const long double eps = 1e-8;
void solve() {
int n;
cin >> n;
std::vector<int> a(n + 1, 0);
for (int i = 1; i <= n; i ++) cin >> a[i];
int res = 0, lst = 0;
for (int i = 2; i <= n; i ++) {
if (a[i - 1] == 1) continue;
int j = floor(log2((long double)log(a[i]) * 1.0 / log(a[i - 1])));
if (j >= lst) { lst = 0; continue; }
if (a[i] == 1) {
cout << -1 << endl;
return;
}
int k = ceil((long double)lst * 1.0 - log2(log(a[i]) * 1.0 / log(a[i - 1])));
res += k, lst = k;
}
cout << res << endl;
}
signed main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int dt;
cin >> dt;
while (dt --)
solve();
return 0;
}
D. Cases
Problem Statement
You’re a linguist studying a mysterious ancient language. You know that
- Its words consist only of the first c c c letters of the Latin alphabet.
- Each word has a case which can be unambiguously determined by its last letter (different letters correspond to different cases). For example, words “ABACABA” and “ABA” (if they exist) have the same case in this language because they both have the same ending ‘A’, whereas “ALICE” and “BOB” have different cases. If the language does not have a case corresponding to some letter, it means that the word cannot end with this letter.
- The length of each word is k k k or less.
You have a single text written in this language. Unfortunately, as the language is really ancient, spaces between words are missing and all letters are uppercase. You wonder what is the minimum number of cases the language can have. Can you find this out?
Input
Each test consists of several test cases. The first line contains a single integer t t t ( 1 ≤ t ≤ 10 000 1 \le t \le 10\,000 1≤t≤10000) — the number of test cases. It is followed by descriptions of the test cases.
The first line of each test case contains three integers n n n, c c c, k k k ( 1 ≤ k ≤ n ≤ 2 18 1 \le k \le n \le 2^{18} 1≤k≤n≤218, 1 ≤ c ≤ 18 1 \le c \le 18 1≤c≤18) — the length of the text, the number of letters in the language, and the maximum length of the word.
The second line contains a string of n n n characters — the text itself. Each character is one of the first c c c uppercase letters of the Latin alphabet.
It is guaranteed that the sum of n n n over all test cases does not exceed 2 18 2^{18} 218 and the sum of 2 c 2^c 2c over all test cases does not exceed 2 18 2^{18} 218.
Output
For each test case, output a single line consisting of a single integer — the minimum number of cases in the language.
Example
input |
---|
7 |
5 5 1 |
ABCDE |
3 1 2 |
AAA |
3 2 2 |
AAB |
10 2 2 |
ABABABABAB |
4 4 4 |
DCBA |
1 17 1 |
Q |
9 3 2 |
ABCABCABC |
output |
---|
5 |
1 |
2 |
1 |
1 |
1 |
2 |
Note
In the first test case, there must be five cases in the language (for each of the letters ‘A’, ‘B’, ‘C’, ‘D’, and ‘E’ there must be a case that has a corresponding ending).
In the fourth test case, one case with ending ‘B’ is sufficient.
Solution
具体见文后视频。
Code
#include <bits/stdc++.h>
#define fi first
#define se second
#define int long long
using namespace std;
typedef pair<int, int> PII;
typedef long long LL;
void solve() {
int n, k, c;
string s;
cin >> n >> c >> k >> s;
s = ' ' + s;
std::vector<int> cnt(c, 0), st(1 << c, 0);
int mask = 0;
for (int i = 1; i <= k; i ++) cnt[s[i] - 'A'] ++, mask |= (1 << s[i] - 'A');
st[((1 << c) - 1) ^ mask] = 1;
for (int i = k + 1; i <= n; i ++) {
cnt[s[i - k] - 'A'] --; if (!cnt[s[i - k] - 'A']) mask ^= (1 << s[i - k] - 'A');
cnt[s[i] - 'A'] ++, mask |= (1 << s[i] - 'A');
st[((1 << c) - 1) ^ mask] = 1;
}
for (int j = 0; j < c; j ++)
for (int i = (1 << c) - 1; i >= 0; i --)
if (i >> j & 1) st[i ^ (1 << j)] |= st[i];
int res = 1e18;
for (int i = 0; i < 1 << c; i ++)
if (!st[i] && ((i >> s[n] - 'A') & 1)) res = min(res, (int)__builtin_popcount(i));
cout << res << endl;
}
signed main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int dt;
cin >> dt;
while (dt --)
solve();
return 0;
}
E1. Let Me Teach You a Lesson (Easy Version)
Problem Statement
This is the easy version of a problem. The only difference between an easy and a hard version is the constraints on t t t and n n n. You can make hacks only if both versions of the problem are solved.
Arthur is giving a lesson to his famous 2 n 2 n 2n knights. Like any other students, they’re sitting at the desks in pairs, but out of habit in a circle. The knight 2 i − 1 2 i - 1 2i−1 is sitting at the desk with the knight 2 i 2 i 2i.
Each knight has intelligence, which can be measured by an integer. Let’s denote the intelligence of the i i i-th knight as a i a_i ai. Arthur wants the maximal difference in total intelligence over all pairs of desks to be as small as possible. More formally, he wants to minimize max 1 ≤ i ≤ n ( a 2 i − 1 + a 2 i ) − min 1 ≤ i ≤ n ( a 2 i − 1 + a 2 i ) \max\limits_{1 \le i \le n} (a_{2 i - 1} + a_{2 i}) - \min\limits_{1 \le i \le n} (a_{2 i - 1} + a_{2 i}) 1≤i≤nmax(a2i−1+a2i)−1≤i≤nmin(a2i−1+a2i).
However, the Code of Chivalry only allows swapping the opposite knights in the circle, i.e., Arthur can simultaneously perform a i : = a i + n a_i := a_{i + n} ai:=ai+n, a i + n : = a i a_{i + n} := a_i ai+n:=ai for any 1 ≤ i ≤ n 1 \le i \le n 1≤i≤n. Arthur can make any number of such swaps. What is the best result he can achieve?
Input
Each test consists of several test cases. The first line contains a single integer t t t ( 1 ≤ t ≤ 1000 1 \le t \le 1000 1≤t≤1000) — the number of test cases. It is followed by descriptions of the test cases.
The first line of each test case contains a single integer n n n ( 1 ≤ n ≤ 2000 1 \le n \le 2000 1≤n≤2000) — the number of desks.
The second line consists of 2 n 2n 2n integers a 1 , a 2 , … , a 2 n a_1, a_2, \ldots, a_{2 n} a1,a2,…,a2n ( 1 ≤ a i ≤ 1 0 9 1 \le a_i \le 10^9 1≤ai≤109) — the intelligence values of the knights.
It is guaranteed that the sum of n n n over all test cases does not exceed 2000 2000 2000.
Output
For each test case, output a single line containing one integer — the minimal difference Arthur can achieve.
Example
input |
---|
5 |
2 |
6 6 4 4 |
1 |
10 17 |
3 |
1 10 1 10 1 10 |
3 |
3 3 4 5 5 4 |
5 |
1 2 3 4 5 6 7 8 9 10 |
output |
---|
0 |
0 |
0 |
2 |
4 |
Note
In the first test case, Arthur can swap the second and the fourth knights. Then the total intelligence at both desks will be 10 10 10.
In the third test case, Arthur can make 0 0 0 operations, which will result in the total intelligence of 11 11 11 at each of the desks.
In the fourth test case, Arthur can swap knights with indices 2 2 2 and 5 5 5 and achieve the difference of 2 2 2. It can be proven that he cannot improve his result any further.
Solution
具体见文后视频。
Code
#include <bits/stdc++.h>
#define fi first
#define se second
#define int long long
using namespace std;
typedef pair<int, int> PII;
typedef long long LL;
const int N = 4e3 + 10;
int n;
int a[N], dp[N][2];
void solve() {
cin >> n;
for (int i = 1; i <= 2 * n; i ++) cin >> a[i];
if (n % 2 == 0) {
int mn = 1e18, mx = -1e18;
for (int i = 1; i < n; i += 2) {
int A = a[i], B = a[i + 1], C = a[i + n], D = a[i + n + 1];
if (abs(A + B - C - D) > abs(A + D - B - C)) swap(B, D);
mx = max({mx, A + B, C + D}), mn = min({mn, A + B, C + D});
}
cout << mx - mn << endl;
} else {
if (n == 1) {
cout << 0 << endl;
return;
}
int res = 1e18;
for (int i = 1; i <= 2 * n; i += 2) {
std::vector<int> b;
int p = i; b.push_back(p);
while (p != i + 1) {
if (p <= n) p += n; else p -= n;
b.push_back(p);
if (p == i + 1) break;
if (p & 1) p ++; else p --;
b.push_back(p);
}
for (int j = 0; j < 2; j ++)
for (int k = 0; k < 2; k ++) {
memset(dp, 0x3f, sizeof dp);
int A = !j ? a[i] : a[b[1]], B = !k ? a[i + 1] : a[b[2 * n - 2]], mn = A + B;
dp[0][j] = mn;
for (int po = 1; po < 2 * n - 1; po += 2)
for (int lst = 0; lst < 2; lst ++)
for (int now = 0; now < 2; now ++) {
int A = !lst ? a[b[po]] : a[b[po - 1]], B = !now ? a[b[po + 1]] : a[b[po + 2]];
if (A + B < mn) continue;
dp[po][now] = min(dp[po][now], max(dp[max(po - 2, 0ll)][lst], A + B));
}
res = min(res, dp[2 * n - 3][k] - mn);
}
}
cout << res << endl;
}
}
signed main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int dt;
cin >> dt;
while (dt --)
solve();
return 0;
}
视频讲解
Codeforces Round 961 (Div. 2)(A ~ E1 题)
最后祝大家早日