# |
Author |
Problem |
Lang |
Verdict |
Time |
Memory |
Sent |
Judged |
|
109589906 |
Contestant:
Tsovak |
1496B
- 22
|
C++17 (GCC 7-32)
|
Time limit exceeded on pretest 2
|
1000 ms
|
165556 KB
|
2021-03-10 15:58:27 |
2021-03-10 15:58:28 |
|
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <set>
//#include <unordered_set>
#include <map>
//#include <unordered_map>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <fstream>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define mpr make_pair
#define ff first
#define ss second
ll gcd(ll a, ll b)
{
if (a == 0)
return b;
if (b == 0)
return a;
if (a == b)
return a;
if (a > b)
return gcd(a - b, b);
return gcd(a, b - a);
}
bool prime(ll a)
{
for (ll i = 2; i * i <= a; i++)
if (a % i == 0)
return false;
return true;
}
map<int, int> mp;
multiset<int> st;
set<int> st0;
vector<int> v;
void solve()
{
int i, j;
int k, n, a;
st.clear();
st0.clear();
v.clear();
mp.clear();
cin >> n >> k;
for (i = 0; i < n; i++) {
cin >> a;
st.insert(a);
st0.insert(a);
}
int ind, maxx, mexx;
for (auto i : st0) {
v.push_back(i);
}
i = 0;
for (j = 0; j < k; j++) {
if (v[0] != 0)
mexx = 0;
else {
mexx = -1;
for (i; i < n - 1; i++) {
if (v[i] + 1 < v[i + 1]) {
mexx = v[i] + 1;
break;
}
}
if (mexx == -1)
mexx = v[v.size() - 1] + 1;
}
maxx = v[v.size() - 1];
int d = (maxx + mexx + 1) / 2;
//cout << maxx << ' ' << mexx << ' ' << d << endl;
if (mp[d] == 1) {
break;
}
st0.insert(d);
mp[d] = 1;
auto it = upper_bound(v.begin(), v.end(), d - 1);
v.insert(it, d);
}
cout << st0.size() << endl;
return;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t = 1, tt;
cin >> t;
for (tt = 0; tt < t; tt++) {
solve();
}
return 0;
}
Click to see test details