Submission #667597

#TimeUsernameProblemLanguageResultExecution timeMemory
667597LFFBTable Tennis (info1cup20_tabletennis)C++14
35 / 100
3107 ms691920 KiB
#include <iostream> #include <vector> #include <map> #include <algorithm> #define debug(args...) //printf(args) typedef long long llong; const int MAX_N = 16e4; const int MAX_V = 2e9 + 10; int n, m, k; llong sum, th; int input[MAX_N]; std::map<int, int> map; int possible; std::vector<std::pair<int, int>> pairs; int output[MAX_N]; int main() { scanf("%d %d", &n, &k); m = n + k; for (int i = 0; i < m; i++) { scanf("%d", &input[i]); sum += input[i]; } th = sum / ((n+k) / 2); std::sort(input, input+n+k); for (int i = 0; i < m; i++) { for (int j = i+1; j < m; j++) { int s = input[i] + input[j]; if (s > th) break; map[s]++; } } for (std::pair<int, int> pair : map) { debug("%d %d\n", pair.first, pair.second); if (pair.second >= n/2) { possible = pair.first; break; } } debug("chose %d\n", possible); for (int i = 0; i < m; i++) { for (int j = i+1; j < m; j++) { if (input[i] + input[j] == possible) { pairs.push_back({input[i], input[j]}); } } } debug("got %d pairs\n", (int)pairs.size()); for (int i = 0; i < n/2; i++) { std::pair<int, int> pair = pairs[i]; debug("inserting %d and %d\n", pair.first, pair.second); output[2*i ] = pair.first; output[2*i+1] = pair.second; } std::sort(output, output+n); for (int i = 0; i < n; i++) { printf("%d ", output[i]); } printf("\n"); }

Compilation message (stderr)

tabletennis.cpp: In function 'int main()':
tabletennis.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
tabletennis.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         scanf("%d", &input[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~
#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...