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: