답안 #436377

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
436377 2021-06-24T13:05:11 Z PiejanVDC 사탕 분배 (IOI21_candies) C++17
컴파일 오류
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) {
    vector<int>sum(c.size()+1,0);
    for(int i = 0 ; i < v.size() ; i++) {
        sum[l[i]]+=v[i],sum[r[i]+1]-=v[i];
    }
    vector<int>ans(n,0);
    int current_sum=0;
    for(int i = 0 ; i < c.size() ; i++) {
            current_sum+=sum[i];
            ans[i] = min(c[i],current_sum);
    }
    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:7:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 |     for(int i = 0 ; i < v.size() ; i++) {
      |                     ~~^~~~~~~~~~
candies.cpp:10:20: error: 'n' was not declared in this scope
   10 |     vector<int>ans(n,0);
      |                    ^
candies.cpp:12:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     for(int i = 0 ; i < c.size() ; i++) {
      |                     ~~^~~~~~~~~~