# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
888304 | raul2008487 | Table Tennis (info1cup20_tabletennis) | C++17 | 27 ms | 6244 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 pos){
ll l = bg, r = ed, s1 = d[bg], s2 = d[ed];
vl bad, res;
while(l < r && pos <= k){
if(s1 == s2){
l++;
r--;
}
else if(s1 < s2){
l++;
bad.pb(l);
s1 += d[l];
}
else{
bad.pb(r);
r--;
s2 += d[r];
}
}
ll ptr = 0;
for(int g = bg; g <= ed+1; g++){
if(ptr < bad.size() && bad[ptr] == g){ptr++;continue;}
res.pb(v[g]);
}
for(auto x: res){
cout << x << ' ';
}
cout << endl;
}
bool check(ll bg, ll ed, ll pos){
ll l = bg, r = ed, s1 = d[bg], s2 = d[ed];
ll cnt = 1;
if( l > r){return false;}
while(l < r && pos <= k){
if(s1 == s2){
l++;
r--;
cnt++;
}
else if(s1 < s2){
l++;
pos++;
s1 += d[l];
}
else{
r--;
pos++;
s2 += d[r];
}
}
return (cnt == (n/2) && pos == k);
}
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 - 2 - j, i + j)){
print(i, m - 2 - j, i + j);
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... |