Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using ll = long long;
- const ll OO = ll(4e18);
- const ll N = 400400;
- int c[505] ,d[505] ,ans[N];
- int n ,T ,idx;
- ll dp[N];
- bool getAns(int t)
- {
- if( t == 0 ) return true;
- bool res = false;
- for(int i = 0 ; i < n ; i++)
- {
- if( 0 <= t - c[i] && t - c[i] <= 2 * T )
- {
- if( dp[t] - 1ll * d[i] == dp[t - c[i]] )
- {
- if( getAns(t - c[i]) )
- {
- ans[idx ++] = i;
- res = true;
- break;
- }
- }
- }
- }
- return res;
- }
- void calcBottomUp()
- {
- for(int t = 0 ; t < N ; t++) dp[t] = OO;
- dp[0] = 0ll;
- for(int t = 0 ; t <= 2 * T ; t++)
- if( dp[t] != OO )
- for(int i = 0 ; i < n ; i++)
- if( c[i] != 0 && 0 <= t + c[i] && t + c[i] <= 2 * T )
- dp[t + c[i]] = min(dp[t + c[i]] ,dp[t] + 1ll * d[i]);
- getAns(T);
- }
- int main()
- {
- scanf("%d%d" ,&n ,&T);
- n += 1;
- c[0] = d[0] = 1;
- for(int i = 1 ; i < n ; i++)
- {
- scanf("%d" ,&c[i]);
- scanf("%d" ,&d[i]);
- }
- calcBottomUp();
- printf("%d\n" ,idx);
- for(int i = 0 ; i < idx ; i++){
- printf("%d " ,ans[i] + 1);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement