I have wrote this code to solve this problem:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include <iostream>
using namespace std;
int main ()
{
int d, n, t, a, b; //d=expenses, t=weeks, n=saved euros
int count = 0; //a=weekly allowance, b=balance
cin >> d >> n >> t; //count=number of weeks with positive balance
if ( t == 0 and n >= d ) //if there are no weeks i just have to compare
{ //saved euros and expenses
cout << 1 << endl;
}
else
{
for ( int i = 0; i < t; ++i )
{
cin >> a;
b = n + a - d; //calculate the balance of every week till week "t"
if ( b >= 0 ) //if it is positive, then add 1 to the counter
{
++count;
}
b = 0;
}
cout << count << endl;
}
}
|
We use a tool to "judge" if the code solves the problem or not. This tool executes the code with public and private samples. The code passes the public ones but not the private ones. I have tried different things as being certain values 0 but privates say wrong answer. I do not know what else is missing in this code. Some kind of help would be thanked!
"
You have saved n euros. Additionally, every Monday of the next t weeks, you will be given a weekly allowance of a1, a2, ..., at euros, respectively. Every week, you have a fixed amount of expenses that sums up to d euros.
Write a program that counts how many weeks you end up with a strictly positive balance.
Input
The input consists of three naturals d ≥ 0, n ≥ 0 and t> 0, which represent fixed weekly expenses, the initial savings, and the number of weeks with allowance, respectively.
Following, there are the quantities corresponding to the t weekly allowances a1, ..., at . Every week allowance is a natural number ai≥ 0.
Output
The output is a natural number indicating the number of weeks which end up with a strictly positive balance, after paying the weekly expenses.
Your program must meet the output format described in the examples an it should follow a right programming style. You may also decide to include comments, if appropriate.
"