Submission #524391

# Submission time Handle Problem Language Result Execution time Memory
524391 2022-02-09T07:04:37 Z mateigg4 Table Tennis (info1cup20_tabletennis) C++14
Compilation error
0 ms 0 KB
#include <fstream>
#include <map>
#include <algorithm>
#include <cmath>
#define nmax 160000
#pragma GCC optimize("Ofast")
#define int long long
 
using namespace std;
 
int v[nmax + 1];
pair<int, int> sol[nmax + 1];
map<int, int> f;
 
int main()
{
    int n, k, i, j, x, y, st, dr, s, p;
    cin >> n >> k;
    for (i = 1; i <= n + k; i++)
        cin >> v[i];
    sort(v + 1, v + n + k + 1);
    for (x = 0; x < 2 * k; x++)
        for (y = n + k + 1; y > n - k; y--)
        {
            if (x + n + k - y <= k && f[v[x + 1] + v[y - 1]] == 0)
            {
                s = v[x + 1] + v[y - 1];
                // cout << s << endl;
                p = 0;
                st = x + 1, dr = y - 1;
                for (i = st; i <= dr; i++)
                {
                    while (dr > i && v[i] + v[dr] > s)
                        dr--;
                    if (v[i] + v[dr] == s && p < n / 2)
                    {
                        sol[p++] = {v[i], v[dr]};
                        // cout << v[i] << " " << v[dr] << endl;
                    }
                }
                if (p >= n / 2)
                {
                    for (i = 0; i < n / 2; i++)
                        cout << sol[i].first << " ";
                    for (i = n / 2 - 1; i >= 0; i--)
                        cout << sol[i].second << " ";
                    return 0;
                }
                f[s]++;
            }
            else
                break;
        }
    return 0;
}

Compilation message

cc1plus: error: '::main' must return 'int'
tabletennis.cpp: In function 'int main()':
tabletennis.cpp:18:5: error: 'cin' was not declared in this scope
   18 |     cin >> n >> k;
      |     ^~~
tabletennis.cpp:5:1: note: 'std::cin' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
    4 | #include <cmath>
  +++ |+#include <iostream>
    5 | #define nmax 160000
tabletennis.cpp:44:25: error: 'cout' was not declared in this scope
   44 |                         cout << sol[i].first << " ";
      |                         ^~~~
tabletennis.cpp:44:25: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
tabletennis.cpp:46:25: error: 'cout' was not declared in this scope
   46 |                         cout << sol[i].second << " ";
      |                         ^~~~
tabletennis.cpp:46:25: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
tabletennis.cpp:17:18: warning: unused variable 'j' [-Wunused-variable]
   17 |     int n, k, i, j, x, y, st, dr, s, p;
      |                  ^