Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <stdio.h>
- const int64_t OO = int64_t(4e18);
- const int64_t offset = 200200;
- const int64_t N = offset * 2;
- const int64_t M = 505;
- int c[M] ,d[M] ,ans[N];
- int64_t dp[M][N];
- int n ,T ,idx;
- int64_t calc(int i ,int t)
- {
- if( t == T ) return 0;
- if( i == n || t < -offset || t > offset ) return OO;
- int64_t &re = dp[i][t + offset];
- if( re != 0 ) return re;
- re = OO;
- re = std::min(re ,calc(i + 1 ,t));
- re = std::min(re ,calc(i ,t + c[i]) + d[i]);
- return re;
- }
- void getAns(int i ,int t)
- {
- if( t == T || i == n || t < -offset || t > offset ) return;
- int64_t re = calc(i ,t);
- if( re == calc(i ,t + c[i]) + d[i] ) {
- ans[idx ++] = i;
- getAns(i ,t + c[i]);
- }
- else getAns(i + 1 ,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]);
- }
- getAns(0 ,0);
- 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