Submission #1145089

#TimeUsernameProblemLanguageResultExecution timeMemory
1145089MedetbekTable Tennis (info1cup20_tabletennis)C++20
Compilation error
0 ms0 KiB
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")
#include <bits/stdc++.h>

#define ll long long
#define int long long
#define all(v) v.begin(), v.end()
#define nl '\n'
#define pb push_back
#define sz(s) (int)(s).size()
#define f first
#define s second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;
const ll N = 1e5+10, MX = 1e18+1, MOD = 1e9 + 7;
void solve(){
    ll n, k;
    cin >> n >> k;
    ll m = n + k;
    ll a[m+1];
    for(int i = 1; i <= m; i++){
        cin >> a[i];
    }
    sort(a + 1, a + 1 + m);
    unordered_map <int, int> cnt;
    vector <int> v;
    set <pair <int, int> > sum;
    for(int i = 1; i <= min(m, k+k+k); i++){
        for(int j = m; j >= max(m-(k+k+k), 1); j--){
            if(i!=j){
                ll sm = a[i]+a[j];
                cnt[sm]++;
                v.pb(sm);
            }
        }
    }
    for(auto x:v){
        if(cnt[x] > 0){
            sum.insert({cnt[x], x});
            cnt[x]=0;
        }
    }
    for(auto [y, x]:sum){
        ll l = 1, r = m; 
        vector <int> ans;
        while(l < r){
            if(a[l] + a[r] > x){
                r--;
            }else if(a[l] + a[r] < x){
                l++;
            }else{
                ans.pb(a[l]);
                ans.pb(a[r]);
                l++;
                r--;
            }
        }
        if(sz(ans) >= n){
            sort(all(ans));
            for(int i = 0; i < n; i++){
                cout << ans[i] << " ";
            }
            return;
        }
    }
}
main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    ll ql =1;
	 while(ql--){
	    solve();
	}
}

Compilation message (stderr)

tabletennis.cpp: In function 'void solve()':
tabletennis.cpp:30:32: error: no matching function for call to 'max(long long int, int)'
   30 |         for(int j = m; j >= max(m-(k+k+k), 1); j--){
      |                             ~~~^~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from tabletennis.cpp:3:
/usr/include/c++/11/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
tabletennis.cpp:30:32: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   30 |         for(int j = m; j >= max(m-(k+k+k), 1); j--){
      |                             ~~~^~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from tabletennis.cpp:3:
/usr/include/c++/11/bits/stl_algobase.h:300:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
tabletennis.cpp:30:32: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   30 |         for(int j = m; j >= max(m-(k+k+k), 1); j--){
      |                             ~~~^~~~~~~~~~~~~~
In file included from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from tabletennis.cpp:3:
/usr/include/c++/11/bits/stl_algo.h:3461:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3461 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3461:5: note:   template argument deduction/substitution failed:
tabletennis.cpp:30:32: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   30 |         for(int j = m; j >= max(m-(k+k+k), 1); j--){
      |                             ~~~^~~~~~~~~~~~~~
In file included from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from tabletennis.cpp:3:
/usr/include/c++/11/bits/stl_algo.h:3467:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3467 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algo.h:3467:5: note:   template argument deduction/substitution failed:
tabletennis.cpp:30:32: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   30 |         for(int j = m; j >= max(m-(k+k+k), 1); j--){
      |                             ~~~^~~~~~~~~~~~~~
tabletennis.cpp: At global scope:
tabletennis.cpp:68:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   68 | main(){
      | ^~~~