Submission #592915

# Submission time Handle Problem Language Result Execution time Memory
592915 2022-07-09T19:56:06 Z Luxry Distributing Candies (IOI21_candies) C++17
Compilation error
0 ms 0 KB
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
	vector<int> s(c.size());
	for (int j = 0; j < v.size(); ++j) {
		if (v[j] > 0) {
			for (int k = l[j]; k <= r[j]; ++k) {
				s[k] = min(c[k], s[k] + v[j]);
			}
		}
		else if (v[j] < 0) {
			for (int k = l[j]; k <= r[j]; ++k) {
				s[k] = max(0, s[k] + v[j]);
			}
		}
	}
	return s;
}

int main()
{
	int n;
	cin >> n;

	vector<int> c(n);

	for (int i = 0; i < n; ++i) {
		cin >> c[i];
	}
    int q;
	cin >> q;

	vector<int> l(q), r(q), v(q);

	for (int i = 0; i < q; ++i) {
		cin >> l[i];
		cin >> r[i];
		cin >> v[i];
	}

	vector<int> result = distribute_candies(c, l, r, v);
	for (int i = 0; i < n; ++i) {
		cout << result[i] << " ";
	}
}

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:8:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |  for (int j = 0; j < v.size(); ++j) {
      |                  ~~^~~~~~~~~~
/usr/bin/ld: /tmp/cc58rbDA.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccBvp7zz.o:candies.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status