#include using namespace std; /*{{{*/ //template #define REP(i,n) for(int i=0;i ostream& operator<<(ostream& os,const vector& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; } template ostream& operator<<(ostream& os,const pair& p){ os << "(" << p.first << ","<< p.second <<")"; return os; } typedef long long ll; typedef unsigned long long ull; typedef pair pii; typedef vector vi; typedef vector vvi; ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); } constexpr ll mod = 1e9+7; const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1}; /*}}}*/ ll N,K; set must; vector dp; bool exist(ll T){ auto id = must.upper_bound(T-K); if(id==must.end()) return false; ll ft = *id; if(abs(ft-T)>N>>K; dp.assign(N+10,0); ll sum=0; vector T(N),D(N); vector> vp; // (cost,time) map t2i; // time->index rep(i,N){ ll a,b; cin>>a>>b; vp.push_back(MP(b,a)); sum+=b; T[i]=a; D[i]=b; } //debug(sum); sort(all(vp)); reverse(all(vp)); for(int i=0;i u(N+10,true); set st; for(int i=0;i=K){ u[i] = false; st.insert(t); } } ll mxv=0; for(int i=0;imxv) must.insert(T[i]); } vector T2,D2; for(int i=0;i max(" << dp[i] << " , " << dp[id]+d <<")" << endl; dp[i+1] = max(dp[i],dp[id]+d); } } } //cerr << "----------" << endl; //for(int i=0;imxv) maxsum += D[i]; int n=T2.size(); cout << sum - (dp[n]+maxsum) << endl; }