题目 | Ntarsis' Set
Codeforces Round 887 (Div. 2)
C. Ntarsis' Set
https://codeforces.com/contest/1853/problem/C
2 seconds / 256 megabytes
standard input / standard output
Problem
Ntarsis has been given a set
What is the smallest element in
Input
Each test contains multiple test cases. The first line contains the number of test cases
The first line of each test case consists of two integers
The following line of each test case consists of
It is guaranteed that:
- The sum of
over all test cases won't exceed ; - The sum of
over all test cases won't exceed ; for all test cases.
Output
For each test case, print an integer that is the smallest element in
Example
Input
7
5 1
1 2 4 5 6
5 3
1 3 5 6 7
4 1000
2 3 4 5
9 1434
1 4 7 9 12 15 17 18 20
10 4
1 3 5 7 9 11 13 15 17 19
10 6
1 4 7 10 13 16 19 22 25 28
10 150000
1 3 4 5 10 11 12 13 14 15
Output
3
9
1
12874
16
18
1499986
Note
For the first test case, each day the
For the second case, each day the
Day | ||
---|---|---|
1 | ||
2 | ||
3 |
The smallest element left after
题解
对于下面这个样例:
ID 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
a[] 1 _ _ _ _ _ 7 _ _ _ _ 12 _ _ _ 16
对于位置为
对于位置为
对于位置为
删除方式如下所示,如果被位置
ID 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
a[] 1 _ _ _ _ _ 7 _ _ _ _ 12 _ _ _ 16
del a a a a a a b a b a b c b a c b
另外,位置
维护方式就是,初始位置
代码
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
const int MAXN = 2e5 + 10;
int a[MAXN];
void solve()
{
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++)
cin >> a[i];
// 该特判其实可以删去,不过加上可以略微提速
if (a[1] != 1)
{
cout << "1" << endl;
return;
}
int pos = 1, nxt = 0;
for (int i = 0; i < k; i++)
{
while (pos + nxt >= a[nxt + 1])
{
if (nxt >= n)
break;
nxt++;
}
pos += nxt;
}
cout << pos << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--)
solve();
return 0;
}
本文采用 CC BY-SA 4.0 许可,本文 Markdown 源码:Haotian-BiJi