Guest User

week16- C1. Zekken Easy, Author Solution

a guest
Dec 9th, 2016
1,095
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define PB push_back
  3. #define F first
  4. #define S second
  5. typedef long long LL;
  6. using namespace std;
  7. const int MOD = 1e9+7;
  8. const int SIZE = 2001;
  9. vector<pair<int,int> > pp;
  10. int dp[SIZE];
  11. int main(){
  12.     int n,d;
  13.     scanf("%d%d",&n,&d);
  14.     pp.PB(make_pair(0,0));
  15.     for(int i=0;i<n;i++){
  16.         int x,y;
  17.         scanf("%d%d",&x,&y);
  18.         pp.PB(make_pair(y,x));
  19.     }
  20.     sort(pp.begin(),pp.end());
  21.     memset(dp,-1,sizeof(dp));
  22.     dp[0]=0;
  23.     int an=0;
  24.     for(int i=1;i<=n;i++){
  25.         for(int j=0;j<i;j++){
  26.             if(dp[j]==-1)continue;
  27.             if(abs(pp[i].S-pp[j].S)<=d*(LL)(pp[i].F-pp[j].F)){
  28.                 dp[i]=max(dp[i],dp[j]+1);
  29.             }
  30.         }
  31.         an=max(an,dp[i]);
  32.     }
  33.     printf("%d\n",an);
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment