#include using namespace std; #define ALL(x) x.begin(),x.end() #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<bool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(b>n; int k=n/3; vector> v(n); rep(i,n) cin>>v[i].first>>v[i].second; sort(ALL(v),[](pair a,pair b){ return a.second>b.second; }); vector> dp(n+1,vector(k+1,LINF)); dp[0][0]=0; rep(i,n){ rep(j,k+1){ // 買う.i-j日目 chmin(dp[i+1][j],dp[i][j]+v[i].first+v[i].second*(0ll+i-j)); // 買わない if(j