Skip to content

Instantly share code, notes, and snippets.

@ch-hristov
Created April 29, 2017 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ch-hristov/91e498c972f92be28b3b6dffac457c2c to your computer and use it in GitHub Desktop.
Save ch-hristov/91e498c972f92be28b3b6dffac457c2c to your computer and use it in GitHub Desktop.
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <map>
#include <math.h>
using namespace std;
int arr[1000001];
int main() {
int t;
scanf("%d",&t);
while(t--){
int n,k,r;
scanf("%d%d%d",&n,&k,&r);
for(int i =0;i<n;i++) arr[i]=0;
for(int i = 0;i<k;i++){
int z;
scanf("%d",&z);
arr[z-1]=1;
}
int total = 0;
for(int i = 0;i<n-r;i++){
int c = 0;
for(int j = i;j<i+r;j++){
if(arr[j]==1){
c++;
}
}
int add = 2 - c;
if(add < 0) add = 0;
total += add;
if(add > 0){
for(int z = i + (r-1);z >= i; z--){
if(arr[z] == 0 && add > 0){
add--;
arr[z]=1;
}
}
}
}
printf("%d",total);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment