# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
888308 | raul2008487 | Table Tennis (info1cup20_tabletennis) | C++17 | 62 ms | 7780 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/// R
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define in insert
#define mpr make_pair
#define vl vector<ll>
//#define endl '\n'
using namespace std;
const int sz = 2e5+5;
const ll inf = 1000000000000000;
//tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> rbt;a
/*struct DSU{
vector<ll> e;
void init(ll n){
e.assign(n+1, -1);
}
ll base(ll x){
if(e[x] < 0){
return x;
}
return e[x] = base(e[x]);
}
bool unite(ll a, ll b){
a = base(a);
b = base(b);
if(a == b){return false;}
if(e[a] > e[b]){
swap(a, b);
}
e[a] += e[b];
e[b] = a;
return true;
}
};*/
ll n, k, m;
vl d, v(sz);
void print(ll bg, ll ed){
ll pl = bg, pr = ed, l = bg + 1, r = ed - 1, cnt = 1;
vl res;
res.pb(v[bg]);res.pb(v[ed]);
while(l < r){
ll s2 = (v[pr] - v[r]);
ll s1 = (v[l] - v[pl]);
if(s1 == s2){
cnt++;
pl = l;
pr = r;
//cout << v[l] << ' ' << v[r] << endl;
res.pb(v[l]);
res.pb(v[r]);
l++;r--;
}
else if(s1 > s2){
r--;
}
else{
l++;
}
}
sort(all(res));
for(int i=0;i<n;i++){
cout << res[i] << ' ';
}cout << endl;
}
bool check(ll bg, ll ed, ll pos){
ll pl = bg, pr = ed, l = bg + 1, r = ed - 1, cnt = 1;
if(l > r){return true;}
while(l < r && pos <= k){
ll s2 = (v[pr] - v[r]);
ll s1 = (v[l] - v[pl]);
if(s1 == s2){
cnt++;
pl = l;
pr = r;
l++;r--;
}
else if(s1 > s2){
r--;
pos++;
}
else{
l++;
pos++;
}
}
cnt *= 2;
return (cnt >= n);
}
void solve(){
ll i, j, bg, ed, pt, w1, w2, cnt, l, r, cc;
cin>>n>>k;
m = n + k;
for(i=0;i<m;i++){
cin>>v[i];
}
for(i=1;i<m;i++){
d.pb(v[i] - v[i-1]);
}
for(i=0;i<=k;i++){
for(j=0;j<=k-i;j++){
if(check(i, m - j - 1, i + j)){
print(i, m - j - 1);
return ;
}
}
}
//assert(0);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t=1;
//cin>>t;
while(t--){
solve();
}
}
/*
6 3
1 2 3 6 7 9 10 12 14
1 3 6 7 10 12
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |