이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tt;
#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())
const int mn = 2e5 + 5;
int a[mn], n, m, k;
int calc (int l, int r) {
int sum = a[l] + a[r], cnt = 1; l++, r--;
while (l <= r) {
while (a[l] + a[r] > sum) r--;
if (a[l] + a[r] == sum) cnt++, r--;
l++;
}
return cnt;
}
void findAns (int sum) {
int l = 1, r = m;
vector<int> ans;
while (ans.size() < n) {
while (a[l] + a[r] > sum) r--;
if (a[l] + a[r] == sum) {
ans.push_back(a[l]);
ans.push_back(a[r]);
r--;
}
l++;
}
sort(all(ans));
for (int u : ans) cout << u << " ";
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
m = n + k;
for (int i = 1; i <= m; i++) cin >> a[i];
for (int l = 1; l <= k + 1; l++)
for (int r = m; m - r + l - 1 <= k; r--)
if (calc(l, r) >= n / 2) return findAns(a[l] + a[r]), 0;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
tabletennis.cpp: In function 'void findAns(int)':
tabletennis.cpp:30:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
30 | while (ans.size() < n) {
| ~~~~~~~~~~~^~~
# | 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... |