Submission #1365943

#TimeUsernameProblemLanguageResultExecution timeMemory
1365943Charizard2021Boxes with souvenirs (IOI15_boxes)C++20
Compilation error
0 ms0 KiB
#include "boxes.h"
#include<bits/stdc++.h>
using namespace std;
long long delivery(int n, int k, int l, int p[]){
    vector<long long> L;
    vector<long long> R;
    for(long long i = 0; i < n; i++){
        if(p[i] <= l/2){
            L.push_back(p[i]);
        }
        else{
            R.push_back(p[i]);
        }
    }
    vector<long long> prefL((int)L.size());
    for(int i = 0; i < min((int)L.size(), k); i++){
        prefL[i] = 2 * L[i];
    }
    for(int i = k; i < (int)L.size(); i++){
        prefL[i] = prefL[i - k] + 2 * L[i];
    }
    vector<long long> prefR((int)R.size());
    for(int i = (int)R.size() - 1; i >= max(0LL, (int)R.size() - k); i--){
        prefR[i] = 2 * (l - R[i]);
    }
    for(int i = (int)R.size() - k - 1; i >= 0; i--){
        prefR[i] = prefR[i + k] + 2 * (l - R[i]);
    }
    long long ans = 1e18;
    for(long long i = (long long)L.size(); i >= 0; i--){
        for(long long j = 0; j <= (long long)R.size(); j++){
            long long val = ((long long)L.size() - i) + j;
            val = (val + (k - 1))/k;
            val *= l;
            long long val2 = (i == 0 ? 0 : prefL[i - 1]) + (j == (int)R.size() ? 0 : prefR[j]);
            ans = min(ans, val + val2);
        }
    }
    return ans;
}
// int main(){
//     int n, k, l;
//     cin >> n >> k >> l;
//     int p[n];
//     for(int i = 0; i < n; i++){
//         cin >> p[i];
//     }
//     cout << delivery(n, k, l, p) << "\n";
// }

Compilation message (stderr)

boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:23:44: error: no matching function for call to 'max(long long int, int)'
   23 |     for(int i = (int)R.size() - 1; i >= max(0LL, (int)R.size() - k); i--){
      |                                         ~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from boxes.cpp:2:
/usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
boxes.cpp:23:44: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   23 |     for(int i = (int)R.size() - 1; i >= max(0LL, (int)R.size() - k); i--){
      |                                         ~~~^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note:   template argument deduction/substitution failed:
boxes.cpp:23:44: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   23 |     for(int i = (int)R.size() - 1; i >= max(0LL, (int)R.size() - k); i--){
      |                                         ~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:61:
/usr/include/c++/13/bits/stl_algo.h:5795:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5795 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note:   template argument deduction/substitution failed:
boxes.cpp:23:44: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   23 |     for(int i = (int)R.size() - 1; i >= max(0LL, (int)R.size() - k); i--){
      |                                         ~~~^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5805 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note:   template argument deduction/substitution failed:
boxes.cpp:23:44: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   23 |     for(int i = (int)R.size() - 1; i >= max(0LL, (int)R.size() - k); i--){
      |                                         ~~~^~~~~~~~~~~~~~~~~~~~~~~~