이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx,avx2,fma,sse4.2")
#include<bits/stdc++.h>
#define ll int
#define ii __int128
#define ld long double
#define cd complex<ld>
#define pll pair<int,int>
#define pii pair<int,int>
#define pld pair<ld,ld>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
ll n, k, m;
ll A[200005];
bool check(ll l, ll r)
{
ll remain = k-(l-1)-(m-r);
int i = l, j = r;
vector<ll> save;
ll sum = A[l]+A[r];
//cout << l << " " << r << '\n';
while(j>i&&save.size()<n&&remain>=0)
{
if(A[i]+A[j]==sum)
{
save.push_back(A[i]);
save.push_back(A[j]);
i++; j--;
}
else if(A[i]-A[l]<A[r]-A[j])
{
i++;
remain--;
}
else
{
j--;
remain--;
}
}
if(save.size()==n&&remain>=0)
{
sort(save.begin(),save.end());
for(auto u: save)
{
cout << u<< " ";
}
return 1;
}
return 0;
}
void solve()
{
cin >> n >> k;
m = n+k;
for(int i = 1; i<= m; i++) cin >> A[i];
for(int i = 1; i<= k+1; i++)
{
ll x = k-i+1;
for(int j = m; j>= m-x; j--)
{
if(check(i, j))
{
return;
}
}
}
}
signed main()
{
//ios_base::sync_with_stdio(NULL) ; cin.tie(nullptr) ; cout.tie(nullptr);
int t = 1;// cin >> t;
//cout << -1;
while(t--)
{
solve();
cout << "\n";
}
}
컴파일 시 표준 에러 (stderr) 메시지
tabletennis.cpp: In function 'bool check(int, int)':
tabletennis.cpp:25:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
25 | while(j>i&&save.size()<n&&remain>=0)
| ~~~~~~~~~~~^~
tabletennis.cpp:44:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
44 | if(save.size()==n&&remain>=0)
| ~~~~~~~~~~~^~~
# | 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... |