#include using namespace std; int find(vector T,int value){ int min=-1; int max=T.size(); int mid; while(max-min>1){ mid=(max+min)/2; if(T[mid]>value){ max=mid; }else{ min=mid; } } return min; } int main(){ int N,K; cin>>N>>K; vector T(N),D(N); for(int i=0;i>T[i]>>D[i]; } int m=0; int M=1000000001; int mid; int prev; while(M-m>1){ mid=(m+M)/2; prev=-K; for(int i=0;i dp(N); int ind; long long s=0; for(int i=0;im){ if(ind==-1){ dp[i]=s-D[i]; }else{ dp[i]=dp[ind]-D[i]; } }else{ if(i==0){ dp[i]=s-D[i]; }else if(ind==-1){ dp[i]=min(s-D[i],dp[i-1]); }else{ dp[i]=min(dp[ind]-D[i],dp[i-1]); } } } cout<