Advertisement
Patrickmeme

C - Jumping Takahashi

Jun 14th, 2023
839
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int a[100],b[100];
  6. int curent[10001],ina[10001];
  7.  
  8. int main()
  9. {
  10.     int i,n,x,j;
  11.     cin>>n>>x;
  12.     for(i=0;i<n;i++){
  13.         cin>>a[i]>>b[i];
  14.     }
  15.     ina[0]=1;
  16.     for(i=0;i<n;i++){
  17.         for(j=0;j<=x;j++){
  18.             if(ina[j]==1){
  19.                 if(a[i]+j<=x){
  20.                     curent[a[i]+j]=1;
  21.                 }
  22.                 if(b[i]+j<=x){
  23.                     curent[b[i]+j]=1;
  24.                 }
  25.             }
  26.         }
  27.         for(j=0;j<=x;j++){
  28.             ina[j]=curent[j];
  29.             curent[j]=0;
  30.         }
  31.     }
  32.     if(ina[x]==1)
  33.         cout<<"Yes";
  34.     else
  35.         cout<<"No";
  36.     return 0;
  37. }
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement