WA on #2 求调
查看原帖
WA on #2 求调
951739
ZBH_123楼主2024/6/1 11:12
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const int maxn=1e5;
int n,p;
struct node{
	int m,c,id;
}a[maxn+5];

bool cmp(node x,node y){
	return x.c<y.c;
}

void solve(){
	cin>>n>>p;
	for(int i=1;i<=n;i++){
		cin>>a[i].m;
		a[i].id=i;
	}
	for(int i=1;i<=n;i++) cin>>a[i].c;
	a[n+1].c=p,a[n+1].m=n;
	
	sort(a+1,a+n+2,cmp);
	int cnt=0;
	ll ans=0;
	for(int i=1;i<=n+1;i++){
		if(cnt<n&&a[i].id) ans+=p,cnt++;
		while(cnt<n&&a[i].m){
//			cerr<<a[i].id<<endl;
			ans+=a[i].c,cnt++,a[i].m--;
		}
	}
	
	cout<<ans<<endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    int T=1;
	cin>>T;
    while(T--) solve();
    return 0;
}
2024/6/1 11:12
加载中...