求助!样例过不去
查看原帖
求助!样例过不去
566190
我是歌者楼主2024/9/23 19:19
#include<bits/stdc++.h>
#define N 1e6+10
using namespace std;
struct s{
	long long int w;
	long long int q;
}store[1000010];
bool cmp(s a,s b){
	return a.w<b.w;
}
long long int n,m,r,mike[1000010],rent[1000010];
int main(){
	cin>>n>>m>>r;
	for(int i=1;i<=n;i++){
		cin>>mike[i];
	}
	for(int i=1;i<=m;i++){
		cin>>store[i].w;
		cin>>store[i].q;
	}
	for(int i=1;i<=r;i++){
		cin>>rent[i];
	}
	
	sort(mike+1,mike+n+1);
	sort(store+1,store+m+1,cmp);
	sort(rent+1,rent+r+1);
	long long int idx=1,idx2=1,flag1=0,flag2=0,ans=0,aa;
	for(int i=1;i<=n;i++){
		aa=mike[i];
		while (aa>store[idx].q&&store[idx].q!=0){
			flag1+=store[idx].q*store[idx].w;
			aa-=store[idx].q;
			idx++;
		}
		if(aa!=0){
			flag1+=aa*store[idx].w;
			store[idx].q-=aa;
			
		}
		flag2=rent[idx2];
		if(flag1>=flag2){
			ans+=flag1;
			flag1=0;
			flag2=0;
		}
		else{
			ans+=flag2;
			idx2++;
			n-=1;
			flag1=0;
			flag2=0;
		}
		
	}
	cout<<ans;
	
}
2024/9/23 19:19
加载中...