cf 1020 C
2 seconds
256 megabytes
standard input
standard output
As you know, majority of students and teachers of Summer Informatics School live in Berland for the most part of the year. Since corruption there is quite widespread, the following story is not uncommon.
Elections are coming. You know the number of voters and the number of parties — nn and mm respectively. For each voter you know the party he is going to vote for. However, he can easily change his vote given a certain amount of money. In particular, if you give ii-th voter cici bytecoins you can ask him to vote for any other party you choose.
The United Party of Berland has decided to perform a statistical study — you need to calculate the minimum number of bytecoins the Party needs to spend to ensure its victory. In order for a party to win the elections, it needs to receive strictly more votes than any other party.
The first line of input contains two integers nn and mm (1≤n,m≤30001≤n,m≤3000) — the number of voters and the number of parties respectively.
Each of the following nn lines contains two integers pipi and cici (1≤pi≤m1≤pi≤m, 1≤ci≤1091≤ci≤109) — the index of this voter's preferred party and the number of bytecoins needed for him to reconsider his decision.
The United Party of Berland has the index 11.
Print a single number — the minimum number of bytecoins needed for The United Party of Berland to win the elections.
1 2
1 100
0
5 5
2 100
3 200
4 300
5 400
5 900
500
5 5
2 100
3 200
4 300
5 800
5 900
600
In the first sample, The United Party wins the elections even without buying extra votes.
In the second sample, The United Party can buy the votes of the first and the fourth voter. This way The Party gets two votes, while parties 33, 44 and 55 get one vote and party number 22 gets no votes.
In the third sample, The United Party can buy the votes of the first three voters and win, getting three votes against two votes of the fifth party.
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <string>
#include <deque>
using namespace std;
#define ll long long
#define gep(i,a,b) for(int i=a;i<=b;i++)
#define gepp(i,a,b) for(int i=a;i>=b;i--)
#define gep1(i,a,b) for(ll i=a;i<=b;i++)
#define gepp1(i,a,b) for(ll i=a;i>=b;i--)
#define N 3009
#define ph push_back
#define inf 10000000000000098
vector<int>ve[N];
int n,m;
ll MIN;
ll solve(ll x){
vector<int>se;
ll ret=,cnt=ve[].size();//初始值
gep(i,,m){
int num=ve[i].size();
gep(j,,num-){
if(num-j>=x){//严格大
ret+=ve[i][j];//必须加到party1上,因为加到别的上面,最后还是加到1上。
cnt++;
}
else{
se.ph(ve[i][j]);
}
}
}
if(cnt<x){
sort(se.begin(),se.end());
for(int i=;i<se.size()&&cnt<x;i++){//在从se里找
ret+=se[i];
cnt++;
}
}
//cnt最后一定是>=x的
return ret;
}
int main()
{
int x;
ll y;
scanf("%d%d",&n,&m);
gep(i,,n){
scanf("%d%lld",&x,&y);
ve[x].ph(y);
}
gep(i,,m)
sort(ve[i].begin(),ve[i].end());
MIN=inf;
gep(i,,n){//枚举查找,不能用二分
MIN=min(MIN,solve(i));
}
printf("%lld\n",MIN);
return ;
}
cf 1020 C的更多相关文章
- ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'
凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- cf Round 613
A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...
- ARC下OC对象和CF对象之间的桥接(bridge)
在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...
- [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现
1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...
- CF memsql Start[c]UP 2.0 A
CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...
- CF memsql Start[c]UP 2.0 B
CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...
- CF #376 (Div. 2) C. dfs
1.CF #376 (Div. 2) C. Socks dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...
- CF #375 (Div. 2) D. bfs
1.CF #375 (Div. 2) D. Lakes in Berland 2.总结:麻烦的bfs,但其实很水.. 3.题意:n*m的陆地与水泽,水泽在边界表示连通海洋.最后要剩k个湖,总要填掉多 ...
随机推荐
- 重写FileUpload控件让它可以显示上传后的文件名
我在以前的开发中经常遇到这样的场景:文件上传之后需要显示文件名,但是asp.net自带的fileupload是不能付给上传后的文件名值的. 以前都是做一个label显示的,今天想起来了,写个控件封装一 ...
- [总结] min-25筛
再不写总结我又会忘掉啊啊啊啊啊啊啊啊啊 这个\(min-25\)筛主要用来求一个积性函数的前缀和,就像这样\[\sum_{i=1}^n f(i)\] 不过这个积性函数要满足两个条件:质数\(p\)的函 ...
- IT圈网红,抢鲜围观
即将于2017年10月23-26日,在北京举办的微软技术暨生态大会,是微软中国年度最盛大的科技峰会,是微软技术大会与合作伙伴大会的首次联袂,也是聚集众多IT大咖的技术狂欢派对. 无论你想实现现代化工作 ...
- jsp另外五大内置对象之out输出
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding= ...
- 【Python图像特征的音乐序列生成】深度卷积网络,以及网络核心
这个项目主要涉及到两个网络,其中卷积神经网络用来提取图片表达的情绪,提取出一个二维向量. 网络结构如图: 词向量采用预训练的glove模型,d=50,其他信息包括了图片的“空旷程度”.亮度.对比度等信 ...
- EF生成的实体映射含义
如图: 组合效果: LEFT JOIN 效果: this.HasOptional(t => t.子表) .WithMany(t => t.主表) .HasForeignKey(d => ...
- MyLinkedList
/** * 节点类 * @author JP * */ class Node { Object value;//节点元素值 Node pre;//上一个节点 Node next;//下一个节点 pub ...
- wine卸载
Wine手动卸载,出现殘留,导致安装其他软件也不成功. 错误如下: 正在读取软件包列表... 完成正在分析软件包的依赖关系树 正在读取状态信息... 完成 您也许需要运行“ap ...
- vue跨域处理(vue项目中baseUrl设置问题)
1.开发环境: 2.生产环境: 然后 const instance = axios.create({ baseURL: process.env.API })
- 《毛毛虫组》【Alpha】Scrum meeting 2
第二天 日期:2019/6/15 1.1 今日完成任务情况以及遇到的问题. 今日完成任务情况: (1)对数据库表进行完善及测试: (2)定义Regex类的IsMatch()方法: (3)进行这一模块代 ...