Submission #448010

# Submission time Handle Problem Language Result Execution time Memory
448010 2021-07-28T13:38:12 Z aris12345678 Distributing Candies (IOI21_candies) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "candies.h"
using namespace std;

const int mxN = 200005;

bool sub2(vector<int> v) {
    int q = int(v.size());
    for(int i = 0; i < q; i++) {
        if(v[i] < 0)
            return false;
    }
    return true;
}

vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
    int n = int(c.size()), q = int(l.size());
    vector<int> ans(n, 0);
    vector<long long> pref(n, 0);
    if(sub2(v)) {
        for(int i = 0; i < q; i++) {
            pref[l[i]] += 1LL*v[i];
            if(r[i] < n)
                pref[r[i]+1] -= 1LL*v[i];
        }
        for(int i = 0; i < n; i++) {
            if(i > 0)
                pref[i] += pref[i-1];
            ans[i] = min(c[i], pref[i]);
        }
    } else {
        for(int i = 0; i < q; i++) {
            for(int j = l[i]; j <= r[i]; j++) {
                if(v[i] > 0)
                    ans[j] = min(c[j], ans[j]+v[i]);
                else
                    ans[j] = max(0, ans[j]+v[i]);
            }
        }
    }
    return ans;
}

Compilation message

candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:29:39: error: no matching function for call to 'min(__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&, __gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&)'
   29 |             ans[i] = min(c[i], pref[i]);
      |                                       ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
candies.cpp:29:39: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
   29 |             ans[i] = min(c[i], pref[i]);
      |                                       ^
In file included from /usr/include/c++/10/bits/specfun.h:45,
                 from /usr/include/c++/10/cmath:1927,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algobase.h:278:5: note:   template argument deduction/substitution failed:
candies.cpp:29:39: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'})
   29 |             ans[i] = min(c[i], pref[i]);
      |                                       ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3468:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3468 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
candies.cpp:29:39: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   29 |             ans[i] = min(c[i], pref[i]);
      |                                       ^
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3474:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3474 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/10/bits/stl_algo.h:3474:5: note:   template argument deduction/substitution failed:
candies.cpp:29:39: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   29 |             ans[i] = min(c[i], pref[i]);
      |                                       ^