Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int cannons[10000010];
- int nc, nload, T, range;
- int main(){
- int x, mxpos;
- scanf("%d %d %d %d", &nc, &nload, &T, &range);
- mxpos = 0;
- for(int i = 1; i <= nc; ++i){
- scanf("%d", &x);
- ++x;
- ++cannons[x];
- mxpos = max(mxpos, x);
- }
- for(int i = 1; i <= mxpos; ++i){
- cannons[i] += cannons[i - 1];
- }
- for(int k = 0; k < T; ++k){
- int cnt = 0;
- int last = 0;
- for(int i = 0; i < nload; ++i){
- scanf("%d", &x);
- ++x;
- int s = max(last + 1, x - range);
- int e = min(mxpos, x + range);
- if(s > e){
- continue;
- }
- cnt += cannons[e] - cannons[s - 1];
- last = e;
- }
- cout << cnt << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement