Help with "Candy Cane Feast" 2023 Dec. Bronze

Candy Cane Feast


Not sure why my code isn’t working.

What I’ve Tried

I have tried downloading test data but it didn’t help me figure it out.

My Work

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

int main() {
	long long n, m;
	long long bottom;
	long long current_cane_units;
	cin >> n >> m;
	vector<long long> cowh;
	for(long long i=0;i<n;i++) {
		long long h;
		cin >> h;
	vector<long long> cane;
	for(long long j=0;j<m;j++) {
		long long k;
		cin >> k;
	for(long long a=0;a<m;a++) {
		bottom = 0;
		current_cane_units = cane[a];
		for(long long b=0;b<n;b++) {
			long long eaten;
			if(cowh[b]>=bottom) {
				eaten = (min(cowh[b]-bottom, cane[a]));
				bottom = cowh[b];
				cowh[b] += (eaten);
				current_cane_units -= eaten;
				if(current_cane_units <= 0) {

	for(long long l=0;l<n;l++) {
		cout << cowh[l] << "\n";

Screenshot of test cases:

Your eaten variable is wrong:

eaten = (min(cowh[b]-bottom, cane[a]));

It should be:

eaten = min(cowh[b],cane[a]) - bottom;

Also, variable bottom is updated wrong. It should be:

bottom += eaten;

See my full solution here: