fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. //ios_base::sync_with_stdio(false);
  6.  
  7. int counts, n, m, s[1000001], a[1000001];
  8.  
  9. cin >> n >> m;
  10. for(int i=0; i<n; i++){cin >> s[i];}
  11. for(int i=0; i<m; i++){cin >> a[i];}
  12.  
  13. for(int i=1; i<m; i++){
  14. a[i]-=a[0];
  15. }
  16. a[0]=0;
  17. bool found;
  18. counts =0;
  19.  
  20. for(int i=0; i<=(n-m); i++){
  21. found=true;
  22. for(int j=i+1; j<i+m; j++){
  23. if((s[j]-s[i])!=a[j-i]){found=false;break;}
  24. }
  25. if(found){counts++;}
  26. }
  27.  
  28. cout << counts;
  29.  
  30. return 0;
  31. }
  32.  
Success #stdin #stdout 0s 11152KB
stdin
10 3
1 2 3 4 5 7 8 9 10 11
10 11 12
stdout
6