aviaryan's blog

By aviaryan, history, 8 years ago, In English

I was trying to solve 732D and after struggling with an optimal algorithm for sometime, I looked into the accepted solutions and saw that many ACs were as simple as the following.

http://codeforces.me/contest/732/submission/21571861

#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;  
}  

I think they will fail on a simple testcase as —

8 2
1 1 1 1 1 1 1 2
1 1

( The ans should be 8 )

Am I understanding the question incorrectly ?

UPDATE It seems like after the contest, some test cases might have been updated/added covering the case above.

  • Vote: I like it
  • +19
  • Vote: I do not like it

»
8 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Yes even I noticed this.The test cases are indeed weak.

  • »
    »
    8 years ago, # ^ |
      Vote: I like it -36 Vote: I do not like it

    Then the testcases IMO were way too weak. I don't do much contests on Codeforces but I am regular on Codechef, there they don't leave these kind of edge cases. The testcases should cover each of the possible edge cases. (This one is too obvious to be even called an edge case)

»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by aviaryan (previous revision, new revision, compare).