Submission #615652

#TimeUsernameProblemLanguageResultExecution timeMemory
615652HamletPetrosyanDistributing Candies (IOI21_candies)C++17
3 / 100
96 ms8416 KiB
#include "candies.h"
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define ll long long
#define add push_back
#define pii pair<int, int>
#define len(a) ((int)(a).size())
#define all(a) a.begin(), a.end()

#define fr first
#define sc second

const int N = 3e5 + 5;

vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
	vector<int> ret;
	if(len(c) <= 2000 && len(l) <= 2000){
		int now = 0;
		for(int i = 0; i < len(c); i++){
			now = 0;
			for(int j = 0; j < len(l); j++){
				if(l[j] <= i && i <= r[j]) {
					if(v[j] < 0) now = max(0, now + v[j]);
					else now = min(c[i], now + v[j]);
				}
			}
			ret.add(now);
		}
		return ret;
	}
	vector<int> dif;
	dif.resize(len(c) + 5, 0);
	for(int i = 0; i < len(l); i++){
		dif[l[i]] += v[i];
		dif[r[i] + 1] -= v[i];
	}
	int now = 0;
	for(int i = 0; i < len(c); i++){
		now += dif[i];
		ret.add(min(now, c[i]));
	}
	return ret;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...