Question: I wrote the following code for the problem but it failed for test cases 8-13 due to runtime error or memory limit exceeded. Can someone

 I wrote the following code for the problem but it failed

I wrote the following code for the problem but it failed for test cases 8-13 due to runtime error or memory limit exceeded. Can someone optimize it such that it'd still work but be more efficient?

#include #include using namespace std;

int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, T; cin >> N >> T; vector haybales(T + 1); for(int i = 0; i > d >> b; haybales[d] = b; } int res = 0; int haybales_today = 0; for(int day = 1; day 0) { res++; haybales_today--; } } cout

return 0; }

Note that the large size of integers involved in this problem may require the use of 64-bit integer data types (e.g., a "long long" in C/C++). SAMPLE INPUT: SAMPLE OUTPUT: 2 Two haybales arrive on the morning of day 1 . Bessie eats one haybale for dinner on day 1 and another haybale on day 2 . On days 3..5, there are no more haybales for Bessie to eat. In total, Bessie eats 2 haybales during the first 5 days. SAMPLE INPUT: Two haybales arrive on the morning of day 1 . Bessie eats one haybale on days 1 and 2 . There are no haybales for Bessie to eat on days 3 and 4 . On the morning of day 5, 10 haybales arrive. Bessie eats one haybale for dinner on day 5 . In total, Bessie eats 3 haybales during the first 5 days. SAMPLE INPUT: SAMPLE OUTPUT: 5 10 haybales arrive on the morning of day 1 . Bessie eats one haybale on days 1..4. On the morning of day 5 , another 10 haybales arrive, meaning there are 16 haybales in the bam. For dinner on day 5 , Bessie eats another haybale. In total, Bessie eats 5 haybales during the first 5 days. SCORING: - Inputs 4-7: T105 - Inputs 8-13: No additional constraints

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!