为什么cnt1会诡异增加
查看原帖
为什么cnt1会诡异增加
726368
kk_is_ethereal楼主2022/10/18 20:13
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline void read(int &x) {
	x=0;
	short flag=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')flag = -1;
		c=getchar();
	}
	while(c >= '0' && c <= '9'){
		x=(x<<3)+(x<<1)+(c^48);
		c=getchar();
	}
	x*=flag;
}
const int inf=0x7fffffff;
int n,m,cnt1[10001],a[10001],b[10001],c[10001];
priority_queue<pair<int,int> >q;
signed main(){
	read(n),read(m);
	for(int i=1;i<=n;i++){
		read(a[i]),read(b[i]),read(c[i]);
		cnt1[i]=1;
		q.push(make_pair(a[i]*cnt1[i]*cnt1[i]+b[i]*cnt1[i]+c[i],i));
	}
	for(int i=1;i<=m;i++){
		printf("%lld ",q.top().first);
		int x=q.top().second;
		cnt1[x]++;
		q.push(make_pair(a[x]*(++cnt1[x])*cnt1[x]+b[x]*cnt1[x]+c[x],x));
		q.pop();
	}
	return 0;
}

2022/10/18 20:13
加载中...