rohansumant's blog

By rohansumant, history, 8 years ago, In English

Consider the following test case

10 3
0 3 0 1 0 0 0 0 2 0
1 1 4

The following AC submission gives the answer as 9. I would like to know how is the answer 9 correct. Since subject 3 requires 4 days of preparation, which clearly isn't possible, shouldn't the answer be -1 ?

#include<bits/stdc++.h>  
using namespace std;  
int main()  
{  
int n,m;  
cin>>n>>m;  
int arr[n+1];  
for(int i=1;i<=n;i++)cin>>arr[i];  
int sum=m,x;  
for(int i=0;i<m;i++){cin>>x; sum+=x;}  
  
for(int i=sum;i<=n;i++)if(arr[i]){cout<<i; return 0;}  
cout<<-1;  
}
  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
8 years ago, # |
  Vote: I like it +5 Vote: I do not like it

It is discussed already here.

That AC submission is from when tests were weak. It is indeed incorrect. Now tests have been fixed.