Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * sin título.cxx
- *
- * Copyright 2018 <oia@oia-vb>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- *
- */
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- using namespace std;
- int DP[10001], N , L,P;
- pair<int,int> in[10001];
- int Caso()
- {
- cin>>N;
- for(int i = 0;i<N;i++)
- scanf("%d %d",&in[i].first,&in[i].second),DP[i] = 0;
- cin>>L>>P;
- DP[N] = 0;
- DP[0] = P;
- for(int i = 0;i<N;i++)
- in[i].first = L - in[i].first;
- sort(in,&in[N]);
- for(int i = 0;i<N;i++)
- {
- for(int j = N-1;j>=0;j--)
- {
- if(DP[j] >= in[i].first && DP[j] + in[i].second > DP[j+1])
- DP[j+1] = DP[j] + in[i].second;
- }
- }
- /*for(int i = 0;i<=N;i++)
- cout<<DP[i]<<" ";
- cout<<endl;*/
- for(int i = 0;i<=N;i++)
- if(DP[i] >= L)
- return i;
- return -1;
- }
- int main()
- {
- #ifdef YO
- freopen("vacas.in","r",stdin);
- #endif
- int T;
- cin>>T;
- while(T--)
- cout<<Caso()<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement