求昨晚 CF Div.3 F
  • 板块学术版
  • 楼主Pink_Cut_Tree
  • 当前回复3
  • 已保存回复3
  • 发布时间2024/7/27 21:47
  • 上次更新2024/7/27 22:07:07
查看原帖
求昨晚 CF Div.3 F
793625
Pink_Cut_Tree楼主2024/7/27 21:47
#include<bits/stdc++.h>
using namespace std;
//#define int long long
const int N=2e5+5;
int T;
int n,k;
int a[N],b[N];
long long cnt;
struct node{
	int fst,snd;
	friend bool operator<(node x,node y){
		if(x.fst==y.fst){
			return x.snd>y.snd;
		}
		return x.fst<y.fst;
	}
};
priority_queue<node>Q;
int main(){
	cin.tie(0)->sync_with_stdio(0);
	cin>>T;
	while(T--){
		cin>>n>>k;
		cnt=0;
		while(!Q.empty()){
			Q.pop();
		}
		for(int i=1;i<=n;i++){
			cin>>a[i];
		}
		for(int i=1;i<=n;i++){
			cin>>b[i];
		}
		for(int i=1;i<=n;i++){
			Q.push({a[i],b[i]});
		}
		while(k--){
			node u=Q.top(); Q.pop();
			cnt+=u.fst;
			Q.push({max(0,u.fst-u.snd),u.snd});
		}
		cout<<cnt<<"\n";
	}
return 0;
}

猜测复杂度 O(n log n),不知为什么 TLE

2024/7/27 21:47
加载中...