Help with "Candy Cane Feast" 2023 Dec. Bronze

Candy Cane Feast
https://usaco.org/index.php?page=viewproblem2&cpid=1347

Question

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;
		cowh.push_back(h);
	}
	vector<long long> cane;
	for(long long j=0;j<m;j++) {
		long long k;
		cin >> k;
		cane.push_back(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) {
					break;
				}
			}

		}
	}
	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:
https://github.com/owenjchen/usaco/blob/main/bronze_2023Dec/usaco2023b_dec_p1.cpp