/// 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;
void print(vl v){
for(auto x: v){
cout << x << ' ';
}
cout << endl;
}
void solve(){
ll i, j, bg, ed, pt, w1, w2, cnt, l, r, cc;
cin>>n>>k;
m = n + k;
vl d, v(m), res;
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++){
bg = i;
ed = m - 2 - j;
cc = i + j;
bool as = 0, tmr = 1;
w1 = 0, w2 = 0;
if(bg > ed){
continue;
}
vl bad;
w1 = d[bg];
w2 = d[ed];
cnt = 1;
while(bg < ed){
if(w1 == w2){
cnt++;
bg++;ed--;
w1 = d[bg];
w2 = d[ed];
tmr = 1;
continue;
}
else if(w1 > w2){
bad.pb(ed);
ed--;
cc++;
w2 += d[ed];
}
else{
bg++;
cc++;
bad.pb(bg);
w1 += d[bg];
}
tmr = 0;
}
if(cc > k){continue;}
if(tmr && cnt == (n/2)){
l = i;
r = m - j - 1;
ll p = 0;
for(pt = l; pt <= r; pt++){
if(p < bad.size() && pt == bad[p]){p++;continue;}
res.pb(v[pt]);
}
if(res.size() != n){continue;}
print(res);
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
tabletennis.cpp: In function 'void solve()':
tabletennis.cpp:100:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
100 | if(p < bad.size() && pt == bad[p]){p++;continue;}
| ~~^~~~~~~~~~~~
tabletennis.cpp:103:31: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
103 | if(res.size() != n){continue;}
| ~~~~~~~~~~~^~~~
tabletennis.cpp:62:18: warning: unused variable 'as' [-Wunused-variable]
62 | bool as = 0, tmr = 1;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
1368 KB |
Output is correct |
2 |
Correct |
24 ms |
7344 KB |
Output is correct |
3 |
Correct |
23 ms |
7356 KB |
Output is correct |
4 |
Correct |
24 ms |
7360 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
7292 KB |
Output is correct |
2 |
Correct |
24 ms |
7356 KB |
Output is correct |
3 |
Correct |
27 ms |
7532 KB |
Output is correct |
4 |
Correct |
31 ms |
7336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Runtime error |
325 ms |
14240 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Execution timed out |
3015 ms |
6476 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |