Codeforces Round #503 (by SIS, Div. 2) C. Elections

还是写个博客吧,整理一下思路

题目链接:C. Elections

大意:n个选民,m个党派,每个选民都有一个初始的投票意向,对于每个选民,你都可以花费ci来让他改变投票目标。问最少花费多少,能让编号为1的党派严格大于其他所有的党派选票。

解题思路:枚举最终选票[1, n],对于每一次假设,计算出该选票要到达第一(也就是让比这个高的降低)的最小花费,维护ans为最小值即可。

这种思路不容易想,想到了就很简单了,%大佬们

AC Code:

#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define pb push_back
#define lowbit(x) x&(-x)
#define PII  pair<int, int> 
#define all(x) x.begin(), x.end()
#define FAST ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = (int)1e9 + 7;
const int maxn = (int)3e3 + 5;
using namespace std;

vector<int> v[maxn];

int main()
{
	int n, m; scanf("%d %d", &n, &m);
	for(int i = 1; i <= n; i++){
		int p, c; scanf("%d %d", &p, &c);
		v[p].pb(c);
	}
	for(int i = 1; i <= m; i++) sort(all(v[i]));
	ll ans = 1e18;
	for(int i = 1; i <= n; i++){
		ll ret = 0;
		int t = v[1].size();
		vector<int> res;
		for(int j = 2; j <= m; j++){
			int need = max(0, (int)v[j].size() - i + 1);
			for(int k = 0; k < need; k++) ret += v[j][k], t++;
			for(int k = need; k < v[j].size(); k++) res.pb(v[j][k]);
		}
		sort(all(res));
		for(int j = 0; j < i - t; j++) ret += res[j];
		ans = min(ret, ans);
	}
	printf("%lld\n", ans);
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值