0分求调!!!
查看原帖
0分求调!!!
1296743
Bh_hurter楼主2024/12/10 22:34

当时考场提交满分,但谷测0分,样例能过(万分感谢!!!)

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
const int N=1e5;
struct node {
	int a,b;
} cara[N+5],carb[N+5];
struct point {
	int p,c;
} st[N+5];
int n,m,px;
int cnta,cntb;
ll ans;
bool cmp(node x,node y) {
	return abs(x.a-x.b)<abs(y.a-y.b);
}
bool cmq(point x,point y) {
	return x.p<y.p;
}
int main() {
	cin>>n>>m>>px;
	for(int i=1; i<=n; i++) {
		cin>>st[i].p>>st[i].c;
	}
	sort(st+1,st+1+n,cmq);
	for(int i=1; i<=m; i++) {
		int x,y;
		cin>>x>>y;
		if(x>=y) cara[++cnta].a=x,cara[cnta].b=y;
		else carb[++cntb].a=x,carb[cntb].b=y;
	}
	sort(cara+1,cara+1+cnta,cmp);
	sort(carb+1,carb+1+cntb,cmp);
	int l=1,r=n;
	while(cnta>0) {
		if(cnta<st[l].c) {
			st[l].c-=cnta;
			while(cnta>0) {
				ans=ans+2ll*cara[cnta].a*st[l].p+2ll*cara[cnta].b*(px-st[l].p);
				cnta--;
			}
		} else {
			for(int i=1; i<=st[l].c; i++) {
				ans=ans+2ll*cara[cnta].a*st[l].p+2ll*cara[cnta].b*(px-st[l].p);
				cnta--;
			}
			l++;
		}
	}
	while(cntb>0) {
		if(cntb<st[r].c) {
			while(cntb>0) {
				ans=ans+2ll*carb[cntb].a*st[r].p+2ll*carb[cntb].b*(px-st[r].p);
				cntb--;
			}
		} else {
			for(int i=1; i<=st[r].c; i++) {
				ans=ans+2ll*carb[cntb].a*st[r].p+2ll*carb[cntb].b*(px-st[r].p);
				cntb--;
			}
			r--;
		}

	}
	cout<<ans;
	return 0;
}
2024/12/10 22:34
加载中...