关于昨晚CF C
  • 板块灌水区
  • 楼主rainygame
  • 当前回复8
  • 已保存回复8
  • 发布时间2023/4/1 08:36
  • 上次更新2023/10/23 19:53:23
查看原帖
关于昨晚CF C
804607
rainygame楼主2023/4/1 08:36

是贪心吧,样例通过代码:

#include <bits/stdc++.h>
using namespace std;
#define MAXN 100001

long long t, n, c, d, last;
long long a[MAXN];
long long ans, cnt;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin >> t;
	
	while (t--){
		cin >> n >> c >> d;
		for (int i=1; i<=n; i++) cin >> a[i];
		sort(a+1, a+n+1);
		ans = c*n+d;
		
		cnt = (a[1]-1)*d;
		last = a[1];
		for (int i=2; i<=n; i++){
			if ((a[i]-last-1)*d >= c || a[i] == last){
				cnt += c;
			}else{
				cnt += (a[i]-last-1)*d;
				last = a[i];
			}
		}
		
		cout << min(ans, cnt) << '\n';
	}
	
	return 0;
}

但是WA了……

2023/4/1 08:36
加载中...