add1ctus

Булевар

Mar 2nd, 2015
617
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int n,m,k;
  9.     cin>>n>>m>>k;
  10.  
  11.     bool edostapno[2][5010];
  12.  
  13.     memset(edostapno,true,10002);
  14.  
  15.     for(int i=0;i<k;i++)
  16.     {
  17.         int temp;
  18.         cin>>temp;
  19.  
  20.         int strana=temp%2;
  21.         temp/=2;
  22.  
  23.         if(strana==0)
  24.             temp--;
  25.  
  26.         for(int j=max(0,temp-m);j<=min(5001,temp+m);j++)
  27.             edostapno[strana][j]=0;
  28.     }
  29.  
  30.     int dodadeni=0;
  31.     for(int i=0;i<n/2;i++)
  32.     {
  33.         if(edostapno[0][i])
  34.         {
  35.             dodadeni++;
  36.             for(int j=i;j<=min(5001,i+m);j++)
  37.                 edostapno[0][j]=false;
  38.         }
  39.     }
  40.     for(int i=0;i<n/2+n%2;i++)
  41.     {
  42.         if(edostapno[1][i])
  43.         {
  44.             dodadeni++;
  45.             for(int j=i;j<=min(5001,i+m);j++)
  46.                 edostapno[1][j]=false;
  47.         }
  48.     }
  49.  
  50.     cout<<dodadeni;
  51.  
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment