1. #include <iostream>
    2. #include <vector>
    3. using namespace std;
    4. const int MAXN = 1000 + 5;
    5. int dp[MAXN][MAXN];
    6. int main() {
    7. int N, V;
    8. cin >> N >> V;
    9. int v[MAXN], w[MAXN];
    10. for (int i = 1; i <= N; i++) cin >> v[i] >> w[i];
    11. for (int i = N; i >= 1; i--)
    12. for (int j = 0; j <= V; j++) {
    13. dp[i][j] = dp[i + 1][j];
    14. if (j >= v[i]) dp[i][j] = max(dp[i][j], dp[i + 1][j - v[i]] + w[i]);
    15. }
    16. int val = V;
    17. for (int i = 1; i <= N; i++) {
    18. if (!val) {
    19. break;
    20. } else if (val - v[i] >= 0 && dp[i][val] == dp[i + 1][val - v[i]] + w[i]) {
    21. cout << i << " ";
    22. val -= v[i];
    23. }
    24. }
    25. }