fork download
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6. ios::sync_with_stdio(false);
  7. cin.tie(0);
  8. // freopen("in.txt","r",stdin);
  9. int n,r,t,cnt=0;
  10. cin>>n>>r;
  11. for (int i = 0; i <= n; cin>>t, ++i)
  12. if(t)
  13. cnt++;
  14.  
  15. if(!cnt){cout<<"-1"<<endl;return 0;}
  16.  
  17. t = ceil((double)n/(2*r-2));
  18. t = (n>0)?t:1;
  19.  
  20. t = (t<=cnt)?t:-1;
  21. cout<<(t)<<endl;
  22.  
  23.  
  24. return 0;
  25. }
  26.  
  27.  
  28.  
Success #stdin #stdout 0s 15232KB
stdin
5 10

0 0 0 0 0
stdout
-1