#include #include #include #include using namespace std; const int N_BURDEN = 105; const int SUM_VALUE = 100005; int N; int value[N_BURDEN], weight[N_BURDEN]; int V; void read() { cin >> N; for (int i = 0; i < N; ++i) { cin >> value[i] >> weight[i]; } cin >> V; } void work() { int maxV[SUM_VALUE]; memset(maxV, -1, sizeof(maxV)); maxV[0] = 0; for (int i = 0; i < N; ++i) { for (int j = SUM_VALUE - 1; j >= 0; --j) { if (maxV[j] != -1) { maxV[j + weight[i]] = max(maxV[j + weight[i]], maxV[j] + value[i]); } } } int idx; for (idx = 0;; ++idx) { if (maxV[idx] == V) { if (idx == 0) ++idx; cout << idx << endl; break; } } if (maxV[accumulate(weight, weight + N, 0)] == V) { cout << "inf" << endl; } else { ++idx; while (maxV[idx] == -1) ++idx; cout << idx - 1 << endl; } } int main() { read(); work(); return 0; }