CF 1020C Elections

题目传送门:https://codeforces.com/problemset/problem/1020/C

C. Elections

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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 cicibytecoins 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.

Input

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.

Output

Print a single number — the minimum number of bytecoins needed for The United Party of Berland to win the elections.

Examples

input

Copy

1 2
1 100

output

Copy

0

input

Copy

5 5
2 100
3 200
4 300
5 400
5 900

output

Copy

500

input

Copy

5 5
2 100
3 200
4 300
5 800
5 900

output

Copy

600

Note

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.

一个学弟给我做的题,还是蛮好的。

大致题意:我们有n个人投票,下面的p[i]和c[i]分别代表的是第i个人投票的人选编号以及你贿赂这个人,让他给你投票需要的花费,你是1号选手,要想获得投票的胜利,最少需要的花费是多少?(这里的票数要严格大于所有人)

n只有3000,n^2的做法肯定可以的,首先想到的是贪心,但是相关联的情况太多了,直接贪心可能解决不了(我写了一下,写拉闸了,就不再想了)

首先把除了1以外所有的投票人放在结构体里,排序。

换个思路,可以直接枚举我们获得投票胜利的票数,假设为x,然后对于每个可以胜利的情况,我们可以倒着遍历,从花费最大的开始,记录每次出现的人当选的票数,如果当前的人选举的人的票数大于x-1了,证明他是对我们造成威胁的,所以开始对于这个人开始标记,并且开始贿赂他,接着再从小到大遍历一次,因为在前面一步,我们已经把所有对我们构造威胁的人都贿赂改票了,那现在只需要加到符合我的x即可,每次选择花费最少的来算进价值里。

每次枚举的时候,再取个min。

还有一些细节处理的地方,大家可以仔细想想,并不难。

代码如下:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll n,m;
struct node {
    int x,y;
} g[3999];
bool cmp(struct node a,struct node  b) {
    return a.y < b.y;
}
int x,y;
int vis[3200];
int vis1[3200];
vector<struct node>v;
int main() {
    while(cin >> n >> m) {
        v.clear();
        int cur = 0;
        for(int i = 1; i <= n; i++) {
            cin >> x >> y;
            struct node gg = node {
                x,y
            };
            if(x != 1) v.push_back(gg);
            else cur++;
        }
        sort(v.begin(),v.end(),cmp);
        ll ans = 1e18;
        for(int i = cur; i <= n; i++) {
            int x = i;
            memset(vis1,0,sizeof(vis1));
            memset(vis,0,sizeof(vis));
            ll sum = 0;
            int num = cur;
            for(int j = v.size() - 1; j >= 0; j--) {
                struct node gg = v[j];
                int id = gg.x;
                int c = gg.y;
                vis1[id]++;
                if(vis1[id] > x - 1) vis[j] = 1,vis1[id]--,sum += c,num++;
            }
            for(int j = 0; j < v.size() && num < i ; j++) {
                if(!vis[j]) {
                    sum += v[j].y;
                    num++;
                }
                if(num >= i) {
                    goto kkk;
                }
            }
            if(num >= i) {
kkk:
//                cout << i <<endl;
                ans = min(ans,sum);
            }
//            cout << sum << "   " << num << endl;
        }
        cout << ans << endl;
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 我可以回答这个问题。以下是20个prometheus监控apiserver指标的例子: 1. apiserver_request_count_total 2. apiserver_request_duration_seconds 3. apiserver_request_latencies_summary 4. apiserver_request_latencies_histogram 5. apiserver_request_size_bytes 6. apiserver_response_size_bytes 7. apiserver_request_duration_seconds_bucket 8. apiserver_request_duration_seconds_sum 9. apiserver_request_duration_seconds_count 10. apiserver_request_latencies_summary_sum 11. apiserver_request_latencies_summary_count 12. apiserver_request_latencies_histogram_bucket 13. apiserver_request_latencies_histogram_sum 14. apiserver_request_latencies_histogram_count 15. apiserver_request_size_bytes_bucket 16. apiserver_request_size_bytes_sum 17. apiserver_request_size_bytes_count 18. apiserver_response_size_bytes_bucket 19. apiserver_response_size_bytes_sum 20. apiserver_response_size_bytes_count ### 回答2: Prometheus是一种开源的监控系统,可以监控和收集各种指标数据。在监控Kubernetes集群中的api-server指标时,我们可以收集以下20个指标数据: 1. api_request_total:api-server接收到的总请求数量。 2. api_request_duration_seconds:api-server处理请求的平均时间。 3. apiserver_current_inflight_requests:当前正在处理的请求数。 4. apiserver_request_latency_seconds:api-server处理请求的延迟时间。 5. etcd_request_rate:对etcd的请求数量。 6. etcd_request_duration_seconds:处理etcd请求的平均时间。 7. etcd_current_inflight_requests:当前正在处理的etcd请求数。 8. etcd_request_latency_seconds:处理etcd请求的延迟时间。 9. apiserver_client_certificate_expiration_seconds:客户端证书的过期时间。 10. apiserver_client_certificate_rotation_age_seconds:客户端证书的轮换时间。 11. apiserver_current_leader:当前的api-server leader。 12. apiserver_storage_errors_total:api-server对存储的错误数量。 13. apiserver_longrunning_duration_seconds:长时间运行的请求的持续时间。 14. etcd_self_metrics_dial_duration_seconds:etcd与自身指标收集的平均连接时间。 15. apiserver_authentication_latency_seconds:api-server进行身份验证的延迟时间。 16. apiserver_authorization_latency_seconds:api-server进行授权的延迟时间。 17. apiserver_request_count:每个请求的计数。 18. apiserver_request_size_bytes:每个请求的大小。 19. apiserver_request_duration_seconds:每个请求的处理时间。 20. apiserver_response_size_bytes:每个请求的响应大小。 以上是其中一些常见的api-server指标,可以用来衡量和监控api-server的性能和健康状态,以便及时发现和解决问题。 ### 回答3: Prometheus是一款开源的监控与警报工具,可以帮助我们监控各种系统、服务和应用程序的指标。下面是一些示例,展示了Prometheus可以监控的Kubernetes API Server的指标: 1. apiserver_request_count_total:API Server接收到的请求数量。 2. apiserver_request_duration_seconds:API Server处理请求的平均时间。 3. apiserver_request_errors_total:API Server处理请求时发生的错误数量。 4. apiserver_flowcontrol_throttled_requests_total:API Server因流量控制而被限制的请求数量。 5. apiserver_audit_event_count_total:API Server生成的审计事件数量。 6. apiserver_etcd_request_duration_seconds:API Server向etcd发送请求的耗时。 7. apiserver_authentication_attempts_total:API Server进行身份验证的尝试次数。 8. apiserver_admission_webhook_latency_seconds:API Server执行准入控制插件的平均时间。 9. apiserver_longrunning_gauge:API Server当前正在执行的长时间运行的操作数量。 10. apiserver_watcher_count:API Server当前活动的观察者数量。 11. apiserver_response_size_bytes:API Server返回的响应大小。 12. apiserver_storage_latency_seconds:API Server执行存储操作的平均延迟。 13. apiserver_storage_throughput_bytes:API Server与底层存储之间传输的数据量。 14. apiserver_node_count:API Server当前已知的集群节点数量。 15. apiserver_etcd_object_counts:API Server当前etcd中存储的对象数量。 16. apiserver_client_errors_total:API Server由于客户端错误而收到的请求数量。 17. apiserver_latency_summary:API Server完成请求所需时间的摘要统计。 18. apiserver_request_duration_bucket:API Server处理请求所需时间的分桶统计。 19. apiserver_request_size_bytes:API Server接收到的请求大小。 20. apiserver_failed_leader_elections_total:API Server发生失败的领导选举的次数。 这些指标可以帮助我们了解API Server的性能、可靠性和负载情况,并及时发现潜在的问题,以确保系统的稳定运行。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值