There are 16 “Tasks”. Each “Task” is a test input file which is provided to your program as input when your submission is evaluated. These Tasks are grouped into subtasks[1] - for example, the Tasks/ test input files 0, 1, 2 3 and 12 are all grouped into Subtask #1.
Let’s see what the constraints section says about Subtask #1:
That means that the test input in each of the Tasks 0, 1, 2, 3 and 12 are guaranteed to have N \le 5000 and Q \le 5000 - this means that a naive O(N \times Q) solution will likely satisfy this Subtask (i.e. will successfully pass Tasks 0, 1, 2 ,3 and 12), and so get at least 20 of the possible 100 points.
[1] Yes, you read that right: a subtask is, rather confusingly, formed out of tasks.
Can’t understand why my program is giving me the wrong answer, I have tested the program with some of the custom inputs mentioned in the comments but its still not working CodeChef: Practical coding for everyone. If somebody can please hep me understand where I am getting it wrong
Day: 1 out of 9 Good
Day: 2 out of 9 Good
Day: 3 out of 9 Not good - price is 463 on day 2 which is <= 701
Day: 4 out of 9 Not good - price is 463 on day 2 which is <= 508
Day: 5 out of 9 Not good - price is 508 on day 4 which is <= 670
Day: 6 out of 9 Not good - price is 508 on day 4 which is <= 638
Day: 7 out of 9 Not good - price is 463 on day 2 which is <= 463
Day: 8 out of 9 Good
Day: 9 out of 9 Not good - price is 394 on day 8 which is <= 402
3
My solution (with extra diagnostic output added) gives:
Day: 1 out of 8 Good
Day: 2 out of 8 Good
Day: 3 out of 8 Good
Day: 4 out of 8 Not good - price is 431 on day 3 which is <= 629
Day: 5 out of 8 Not good - price is 431 on day 3 which is <= 611
Day: 6 out of 8 Good
Day: 7 out of 8 Not good - price is 412 on day 6 which is <= 420
Day: 8 out of 8 Good
5
I marked a price good if it is less than the minimum of the prices of the previous five days.
I am getting WA for this code. Is the algorithm wrong?
Thanks
Here’s my code below:
#include <iostream>
using namespace std;
int main() {
// your code goes here
int t;
cin >> t;
while(t--)
{
int n;
cin >> n;
int arr[n];
for(int i=0;i<n;++i)
cin >> arr[i];
int min = arr[0];
int cnt=1;
for(int i=1;i<n;++i)
{
if(arr[i] < min)
{
cnt++;
min = arr[i];
continue;
}
if(i>=5)
{
int minm = arr[i-5];
for(int j=i-5;j<i;++j)
{
if(arr[j] < minm)
minm = arr[j];
}
min = minm;
}
}
cout << cnt << endl;
}
return 0;
}
On my machine, it gives the wrong answer for the following testcase:
1
8
489 377 605 548 741 625 682 420
The answer should be 3:
Day: 1 out of 8 Good
Day: 2 out of 8 Good
Day: 3 out of 8 Not good - price is 377 on day 2 which is >= 605
Day: 4 out of 8 Not good - price is 377 on day 2 which is >= 548
Day: 5 out of 8 Not good - price is 548 on day 4 which is >= 741
Day: 6 out of 8 Not good - price is 548 on day 4 which is >= 625
Day: 7 out of 8 Not good - price is 625 on day 6 which is >= 682
Day: 8 out of 8 Good
3