玄关
查看原帖
玄关
1366102
Ethan_gong楼主2025/1/24 15:46
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=114514;
int n,m,x,ans;
struct station{
	int p,c;
}r[N];
struct car{
	int a,b;
}t[N];
bool cmp(station x,station y){
	return x.p<y.p;
}
bool cmp2(car x,car y){
	return x.a-x.b>y.a-y.b;
}
signed main(){
	cin>>n>>m>>x;
	for(int i=0;i<n;i++)
		cin>>r[i].p>>r[i].c;
	for(int i=0;i<m;i++)
		cin>>t[i].a>>t[i].b;
	sort(r,r+n,cmp);
	sort(t,t+m,cmp2);
	int s=0,e=n-1;
	for(int i=0;i<m;i++){
		if(t[i].a-t[i].b>0){
			for(int j=s;j<=e;j++){
				if(r[j].c>0ll){
					r[j].c--;
					if(r[j].c==0ll)s++;
					ans+=(r[j].p*t[i].a+(x-r[j].p)*t[i].b)*2;
					break;
				}
			}
		}else{
			for(int j=e;j>=s;j--){
				if(r[j].c>0ll){
					r[j].c--;
					if(r[j].c==0ll)e--;
					ans+=(r[j].p*t[i].a+(x-r[j].p)*t[i].b)*2;
					break;
				}
			}
		}
	}
	cout<<ans;
	return 0;
}

记录

2025/1/24 15:46
加载中...