Submission #448006

# Submission time Handle Problem Language Result Execution time Memory
448006 2021-07-28T13:32:48 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<int> pref(n, 0);
    if(sub2(v)) {
        for(int i = 0; i < q; i++) {
            pref[l[i]] += v[i]
            if(r[i] < n)
                pref[r[i]] -= 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:22:31: error: expected ';' before 'if'
   22 |             pref[l[i]] += v[i]
      |                               ^
      |                               ;
   23 |             if(r[i] < n)
      |             ~~