이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
#define LOCALIO "C:/Users/admin/Documents/Code/"
ll n, k, a[200005];
map <ll, ll> Map;
void Try(ll sum)
{
if (Map[sum]==1)
return;
Map[sum]=1;
ll l=1, r=n+k, num=0, cnt=0;
vector <ll> ans;
while (ans.size()<n && cnt<=k && r>l)
{
while (a[l]+a[r]>sum && r>l)
r--, cnt++;
if (a[l]+a[r]==sum)
ans.pb(a[l]), ans.pb(a[r]), r--;
else cnt++;
l++;
}
if (cnt>k || ans.size()<n)
return;
sort(ans.begin(), ans.end());
for (ll i:ans) cout << i << " ";
exit(0);
}
int main()
{
#ifdef LOCAL
freopen( LOCALIO "input.txt","r",stdin) ;
freopen( LOCALIO "output.txt","w",stdout) ;
#endif
ios_base::sync_with_stdio(NULL); cin.tie(nullptr); cout.tie(nullptr);
// freopen("FIBONACCI.inp","r",stdin);
// freopen("FIBONACCI.out","w",stdout);
cin >> n >> k;
for (ll i=1; i<=n+k; i++)
cin >> a[i];
for (ll i=1; i<=k+1; i++)
for (ll j=n; j<=n+k; j++)
Try(a[i]+a[j]);
}
컴파일 시 표준 에러 (stderr) 메시지
tabletennis.cpp: In function 'void Try(long long int)':
tabletennis.cpp:24:22: 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]
24 | while (ans.size()<n && cnt<=k && r>l)
| ~~~~~~~~~~^~
tabletennis.cpp:33:28: 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]
33 | if (cnt>k || ans.size()<n)
| ~~~~~~~~~~^~
tabletennis.cpp:22:20: warning: unused variable 'num' [-Wunused-variable]
22 | ll l=1, r=n+k, num=0, cnt=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... |