Submission #1105502

#TimeUsernameProblemLanguageResultExecution timeMemory
1105502_callmelucianTable Tennis (info1cup20_tabletennis)C++14
87 / 100
3060 ms4728 KiB
#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; bool valid (int l, int r) { int sum = a[l] + a[r], cnt = 1; l++, r--; while (l <= r) { if (cnt + (r - l + 1) / 2 < cnt) return 0; while (a[l] + a[r] > sum) r--; if (a[l] + a[r] == sum) cnt++, r--; l++; } return cnt >= n / 2; } 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 (valid(l, r)) return findAns(a[l] + a[r]), 0; return 0; }

Compilation message (stderr)

tabletennis.cpp: In function 'void findAns(int)':
tabletennis.cpp:31:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   31 |     while (ans.size() < n) {
      |            ~~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...