Submission #500238

# Submission time Handle Problem Language Result Execution time Memory
500238 2021-12-30T13:41:49 Z sazid_alam Distributing Candies (IOI21_candies) C++17
Compilation error
0 ms 0 KB
#include "candies.h"

#include <bits/stdc++.h>
using namespace std;

vector<int> distribute_candies(vector<int> c, vector<int> l,
                                    vector<int> r, vector<int> v) {
    int n = c.size();
    vector<int> s(n, 0), 
    vector<long long int> sum(n + 1, 0);

    if(n < 2005){
        for(int i = 0; i < (int)v.size(); i++){
            for(int j = l[i]; j <= r[i]; j++){
                if(v[i] > 0) s[j] = min(c[j], s[j] + v[i]);
                else s[j] = max(0, s[j] + v[i]);
            }
        }
        return s;
    }
    else{
        for(int i = 0; i < (int)v.size(); i++){
            sum[l[i]] += v[i] * 1LL;
            sum[r[i] + 1] -= v[i] * 1LL;
        }

        for(int i = 1; i < n; i++) sum[i] += sum[i - 1];
        for(int i = 0; i < n; i++) c[i] = min(c[i] * 1LL, sum[i]);
        return c;
    }
}

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:10:27: error: invalid declarator before 'sum'
   10 |     vector<long long int> sum(n + 1, 0);
      |                           ^~~
candies.cpp:23:13: error: 'sum' was not declared in this scope
   23 |             sum[l[i]] += v[i] * 1LL;
      |             ^~~
candies.cpp:27:36: error: 'sum' was not declared in this scope
   27 |         for(int i = 1; i < n; i++) sum[i] += sum[i - 1];
      |                                    ^~~
candies.cpp:28:59: error: 'sum' was not declared in this scope
   28 |         for(int i = 0; i < n; i++) c[i] = min(c[i] * 1LL, sum[i]);
      |                                                           ^~~