This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a,b) for (int a = 0; a < (b); ++a)
#define pb push_back
#define all(t) t.begin(), t.end()
const int max_N = 160005;
int n = 0, k = 0;
int A[max_N];
vector<int> V;
vector<int> wyn;
inline bool czy_pasuje(int val1, int val2)
{
if (val1 == val2) return false;
wyn = vector<int>();
wyn.pb(val1), wyn.pb(val2);
if (n == 2) return true;
int sum = val1 + val2, lewy_wsk = 0, prawy_wsk = n+k-1, ile_brak = 0;
while(lewy_wsk < prawy_wsk)
{
if(A[lewy_wsk] == val1) ++lewy_wsk;
if(A[prawy_wsk] == val2) --prawy_wsk;
if (A[lewy_wsk] + A[prawy_wsk] == sum)
{
wyn.pb(A[lewy_wsk]), wyn.pb(A[prawy_wsk]);
if (n == wyn.size()) return true;
++lewy_wsk, --prawy_wsk;
}
else if (A[lewy_wsk] + A[prawy_wsk] > sum)
{
--prawy_wsk, ++ile_brak;
}
else
{
++lewy_wsk, ++ile_brak;
}
if (ile_brak > k) return false;
}
return false;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
rep(i,n+k) cin >> A[i];
rep(i,k+1) V.pb(A[i]);
for (int i = n-1; i < n+k; ++i) V.pb(A[i]);
rep(i,V.size())
{
for (int j = i+1; j < V.size(); ++j)
{
if (czy_pasuje(V[i],V[j]) == true)
{
sort(all(wyn));
for (auto v : wyn) cout << v << ' ';
cout << '\n';
return 0;
}
}
}
return 0;
}
Compilation message (stderr)
tabletennis.cpp: In function 'bool czy_pasuje(int, int)':
tabletennis.cpp:28:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | if (n == wyn.size()) return true;
| ~~^~~~~~~~~~~~~
tabletennis.cpp: In function 'int main()':
tabletennis.cpp:4:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
4 | #define rep(a,b) for (int a = 0; a < (b); ++a)
| ^
tabletennis.cpp:54:5: note: in expansion of macro 'rep'
54 | rep(i,V.size())
| ^~~
tabletennis.cpp:56:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for (int j = i+1; j < V.size(); ++j)
| ~~^~~~~~~~~~
# | 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... |