#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define int long long
#define ll long long
#define repp(i,x,n) for(int i=x;i<=n;i++)
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repo(i,x,n) for(int i=x;i>=n;i--)
#define cy cout<<"Yes"<<endl
#define cn cout<<"No"<<endl
#define r0 return 0
#define fi first
#define se second
#define liow ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define jelek cout<<"jelek"<<endl
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define pi pair<pair<int,int>,pair<int,int>>
#define p3 pair<int,pair<int,int>>
#define fl fflush(stdout)
#define lb long double
#define p4 pair<pair<int,int>,pair<int,int>>
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
using namespace std;
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag, tree_order_statistics_node_update>;
const int mod=1e9+7,maxn=2e5+5,N=4e5,INF=1e18,MOD=998244353,LOG=20;
mt19937_64 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
void solve(){
int n,k;cin>>n>>k;
int a[n+k+2];
repp(i,1,n+k) cin>>a[i];
vector<int>ans;
queue<pii>bf;
bf.push({1,n+k});
while(!bf.empty()){
int l=bf.front().fi,r=bf.front().se;bf.pop();
int ah=l,bh=r;
int sum=a[l]+a[r];
int nw=sum;
while(l<=r){
if(sum==nw){
ans.pb(a[l]);
ans.pb(a[r]);
nw-=a[l]+a[r];
l++,r--;
nw+=a[l]+a[r];
} else if(nw<sum){
nw-=a[l];
l++;
nw+=a[l];
} else {
nw-=a[r];
r--;
nw+=a[r];
}
}
if(ans.size()<n){
ans.clear();
} else {
sort(all(ans));
for(int i=0;i<n;i++) cout<<ans[i]<<" ";
return;
}
if(ah+1<=bh){
bf.push({ah+1,bh});
bf.push({ah,bh-1});
}
if(ah+2<=bh) bf.push({ah+1,bh-1});
}
}
signed main(){
liow;
int t=1;
// cin>>t;
while(t--) solve();
}
# | 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... |