Skip to content

Instantly share code, notes, and snippets.

@ch-hristov
Created April 29, 2017 09:55
Show Gist options
  • Select an option

  • Save ch-hristov/91e498c972f92be28b3b6dffac457c2c to your computer and use it in GitHub Desktop.

Select an option

Save ch-hristov/91e498c972f92be28b3b6dffac457c2c to your computer and use it in GitHub Desktop.

Revisions

  1. ch-hristov created this gist Apr 29, 2017.
    56 changes: 56 additions & 0 deletions F.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    #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;

    }