Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Azure SQL Database For Modern Developers Building Applications In The Microsoft Cloud

Authors: Davide Mauri, Silvano Coriani, Anna Hoffma, Sanjay Mishra, Jovan Popovic

1st Edition

1484263693, 978-1484263693

More Books

Students also viewed these Databases questions

Question

6. Effectively perform the managers role in career management.

Answered: 1 week ago