#include #include #include #include #include #include #include using namespace std; //namaega184 int main(){ int n,k;scanf("%d%d",&n,&k); // int w[1000001]={}; int a; map mp; long long ans=0; long long over=0; long long total=0; for(int i=0;i0){ mp[a]--; total-=a; } } else{ int num=0; for(auto it=mp.begin();it!=mp.end();it++){ if(it->firstsecond; if(num>=k)break; } if(num>=k)continue; mp[a]++; total+=a; } } for(auto it=mp.begin();it!=mp.end();it++){ ans+=it->second; } printf("%I64d\n",ans); return 0; }