Submission #625312

# Submission time Handle Problem Language Result Execution time Memory
625312 2022-08-10T03:11:52 Z il9 Distributing Candies (IOI21_candies) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

vector<int> distribute_candies(vector<int> c, vector<long long > l, vector<int> r, vector<int> v)
{
    vector<long long> pre(c.size()+2);
    pre[0]=0;

    int n=c.size();
    for(int i=0;i<r.size()-1;i++)
    {

        pre[l[i]+1]+=v[i];
        pre[r[i]+2]-=v[i];
    }
    for(int i=1;i<=n;i++)
    {
        pre[i]+=pre[i-1];
        //cout<<pre[i]<<" ";
    }
    for(int i=0;i<n;i++)
    {
        if(pre[i+1]>c[i])
        {
            pre[i+1]=c[i];
        }
    }
    for(int i=l[r.size()-1];i<=r[r.size()-1];i++)
    {
        pre[i+1]=max(min(pre[i+1]+v[r.size()-1],c[i]),0);
    }
    for(int i=0;i<n;i++)
    {
        l[i]=pre[i+1];
        //cout<<pre[i+1]<<" ";
    }
    //cout<<"\n";
    return l;
}

Compilation message

candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<long long int>, std::vector<int>, std::vector<int>)':
candies.cpp:10:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     for(int i=0;i<r.size()-1;i++)
      |                 ~^~~~~~~~~~~
candies.cpp:30:53: error: no matching function for call to 'min(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type, __gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&)'
   30 |         pre[i+1]=max(min(pre[i+1]+v[r.size()-1],c[i]),0);
      |                                                     ^
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:30:53: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'})
   30 |         pre[i+1]=max(min(pre[i+1]+v[r.size()-1],c[i]),0);
      |                                                     ^
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:30:53: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'})
   30 |         pre[i+1]=max(min(pre[i+1]+v[r.size()-1],c[i]),0);
      |                                                     ^
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:30:53: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   30 |         pre[i+1]=max(min(pre[i+1]+v[r.size()-1],c[i]),0);
      |                                                     ^
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:30:53: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   30 |         pre[i+1]=max(min(pre[i+1]+v[r.size()-1],c[i]),0);
      |                                                     ^
candies.cpp:38:12: error: could not convert 'l' from 'vector<long long int>' to 'vector<int>'
   38 |     return l;
      |            ^
      |            |
      |            vector<long long int>