Advertisement
Guest User

Vacas a diesel

a guest
Jun 25th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.59 KB | None | 0 0
  1. /*
  2.  * sin título.cxx
  3.  *
  4.  * Copyright 2018  <oia@oia-vb>
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * (at your option) any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  19.  * MA 02110-1301, USA.
  20.  *
  21.  *
  22.  */
  23.  
  24.  
  25. #include <iostream>
  26. #include <cstdio>
  27. #include <algorithm>
  28. using namespace std;
  29. int DP[10001], N , L,P;
  30. pair<int,int> in[10001];
  31. int Caso()
  32. {
  33.     cin>>N;
  34.     for(int i = 0;i<N;i++)
  35.         scanf("%d %d",&in[i].first,&in[i].second),DP[i] = 0;
  36.     cin>>L>>P;
  37.     DP[N] = 0;
  38.     DP[0] = P;
  39.     for(int i = 0;i<N;i++)
  40.         in[i].first = L - in[i].first;
  41.     sort(in,&in[N]);
  42.     for(int i = 0;i<N;i++)
  43.     {
  44.         for(int j = N-1;j>=0;j--)
  45.         {
  46.             if(DP[j] >= in[i].first && DP[j] + in[i].second > DP[j+1])
  47.                 DP[j+1] = DP[j] + in[i].second;
  48.         }
  49.     }
  50.     /*for(int i = 0;i<=N;i++)
  51.         cout<<DP[i]<<" ";
  52.     cout<<endl;*/
  53.     for(int i = 0;i<=N;i++)
  54.         if(DP[i] >= L)
  55.             return i;
  56.     return -1;
  57. }
  58.  
  59. int main()
  60. {
  61.     #ifdef YO
  62.         freopen("vacas.in","r",stdin);
  63.     #endif
  64.     int T;
  65.     cin>>T;
  66.     while(T--)
  67.         cout<<Caso()<<endl;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement