Submission #438753

# Submission time Handle Problem Language Result Execution time Memory
438753 2021-06-28T14:48:55 Z MohamedFaresNebili Distributing Candies (IOI21_candies) C++17
Compilation error
0 ms 0 KB
#include "candies.h"
#include <vector>

std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l,
                                    std::vector<int> r, std::vector<int> v) {
    int n = c.size(); int q = v.size();
    std::vector<int> s(n);
    s.assign(n, 0);
    for(int _=0;_<q;_++) {
        int lo=l[_], hi=r[_];
        for(int i=lo;i<=hi;i++) {
            int k=s[i]+q[_];
            if(q[_]>=0) { k=min(k, c[i]); }
            else { k=max(0, k); }
            s[i]=k;
        }
    }
    return s;
}

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:12:25: error: invalid types 'int[int]' for array subscript
   12 |             int k=s[i]+q[_];
      |                         ^
candies.cpp:13:17: error: invalid types 'int[int]' for array subscript
   13 |             if(q[_]>=0) { k=min(k, c[i]); }
      |                 ^
candies.cpp:13:29: error: 'min' was not declared in this scope; did you mean 'std::min'?
   13 |             if(q[_]>=0) { k=min(k, c[i]); }
      |                             ^~~
      |                             std::min
In file included from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:278:5: note: 'std::min' declared here
  278 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
candies.cpp:14:22: error: 'max' was not declared in this scope; did you mean 'std::max'?
   14 |             else { k=max(0, k); }
      |                      ^~~
      |                      std::max
In file included from /usr/include/c++/10/vector:60,
                 from candies.h:1,
                 from candies.cpp:1:
/usr/include/c++/10/bits/stl_algobase.h:300:5: note: 'std::max' declared here
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~