当前位置: 代码迷 >> 综合 >> death
  详细解决方案

death

热度:28   发布时间:2023-10-29 18:23:30.0

用单调队列维护m个位置,找最小的

#include<cstdio>
#include<queue>
using namespace std;
int n,m;
priority_queue<int>q;
int main(){freopen("death.in","r",stdin);freopen("death.out","w",stdout);scanf("%d%d",&n,&m);for(int i=1;i<=n;i++) {int x;scanf("%d",&x);if(q.size()<m) q.push(-x);else{int tmp=q.top();q.pop();tmp-=x;q.push(tmp);}}printf("%d",-q.top());
}