#include #include #include using namespace std; using ll = long long; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin>>n; vector w(n),s(n); for(int i = 0;i>w[i]>>s[i]; vector idx(n); for(int i = 0;i s[j]; }); vector> dp(n+1,vector(n+1,1e18)); dp[0][0] = 0; for(int i = 0;i=0;i--){ if(dp[n][i]!=1e18){ cout<