社区讨论

WA on #2 求调

CF1876A Helmets in Night Light参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@lwvjhqjb
此快照首次捕获于
2024/06/01 11:14
2 年前
此快照最后确认于
2024/06/01 14:11
2 年前
查看原帖
CPP
#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;
}

回复

0 条回复,欢迎继续交流。

正在加载回复...