在第8组数据上WA了一天,后来才发现问题;

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 200009
#define inf 1e15
using namespace std;
int n,k,q;
struct node
{
int score;
int pain;
bool operator<(const node &t)const
{
return pain<t.pain;
}
} no[maxn]; bool cmp(const node &a,const node &b)
{
return a.score>b.score;
} bool vis[maxn];
int s[maxn]; long long check(int p)
{
long long ans=;
int cnt_1=;
for(int i=;i<=n;i++)
if(no[i].score>=p-)cnt_1++;
cnt_1-=k-;
int cnt_2=;
for(int i=;i<=n&&cnt_2<cnt_1;i++)
{
if(no[i].score==p||no[i].score==(p-))
{
ans+=no[i].pain;
cnt_2++;
vis[i]=;
}
}
for(int i=;i<=n&&cnt_2<p;i++)
{
if(!vis[i])
{
ans+=no[i].pain;
cnt_2++;
}
}
memset(vis,,sizeof vis);
return ans;
} int main()
{
scanf("%d%d",&n,&k);
for(int i=; i<=n; i++)
scanf("%d%d",&no[i].score,&no[i].pain);
sort(no+,no+n+,cmp);
int tar=no[k].score;
sort(no+,no+n+);
long long ans=inf;
for(int i=tar;i<=tar+;i++)
{
if(i>n)break;
ans=min(ans,check(i));
}
if(ans==inf)ans=-;
cout<<ans<<endl;;
}

codeforces 391C3 - The Tournament的更多相关文章

  1. CodeForces - 357C Knight Tournament 伪并查集(区间合并)

    Knight Tournament Hooray! Berl II, the king of Berland is making a knight tournament. The king has a ...

  2. CodeForces - 356A Knight Tournament

    http://codeforces.com/problemset/problem/356/A 首先理解题意 每次给出l 和r  在l - r之间还有资格的选手中得出一个胜者 暴力思路: 首先维护还有资 ...

  3. codeforces 357C Knight Tournament(set)

    Description Hooray! Berl II, the king of Berland is making a knight tournament. The king has already ...

  4. Educational Codeforces Round 13 E. Another Sith Tournament 状压dp

    E. Another Sith Tournament 题目连接: http://www.codeforces.com/contest/678/problem/E Description The rul ...

  5. Educational Codeforces Round 8 A. Tennis Tournament 暴力

    A. Tennis Tournament 题目连接: http://www.codeforces.com/contest/628/problem/A Description A tennis tour ...

  6. Codeforces 678E. Another Sith Tournament(概率DP,状压)

    Codeforces 678E. Another Sith Tournament 题意: n(n<=18)个人打擂台赛,给定任意两人对决的胜负概率,比赛规则:可指定一人作为最开始的擂主,每次可指 ...

  7. Codeforces CF#628 Education 8 A. Tennis Tournament

    A. Tennis Tournament time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. Educational Codeforces Round 13 E. Another Sith Tournament 概率dp+状压

    题目链接: 题目 E. Another Sith Tournament time limit per test2.5 seconds memory limit per test256 megabyte ...

  9. Codeforces Round #207 (Div. 1) A. Knight Tournament (线段树离线)

    题目:http://codeforces.com/problemset/problem/356/A 题意:首先给你n,m,代表有n个人还有m次描述,下面m行,每行l,r,x,代表l到r这个区间都被x所 ...

随机推荐

  1. 关于git reset和git revert之前的区别

    很多时候,git新手容易误操作,比如,在levelIISZ-1.4.dev分支下,运行了git pull idc cpp-1.0的结果,这样做麻烦很大,经常导致maven项目格式不正确,这个时候,可以 ...

  2. 设置apt-get

    1.配置apt-get源 cp /etc/apt/sources.list /etc/apt/sources.listbak #备份原有配置文件 nano /etc/apt/sources.list ...

  3. [原]Unity3d中奇怪的编译错误

    整理项目,重新build时出现一些问题,这些代码在原项目中都是可以运行的. 错误信息如下: Assets/XXXXX.cs(79,35): error CS0103: The name `NNNNNN ...

  4. Verilog-FPGA硬件电路设计之一——if语句优先级(always块中的阻塞赋值生成的组合逻辑电路是按照顺利执行的)

    出处:http://bbs.ednchina.com/BLOG_ARTICLE_3013262.HTM 综合软件:Quartus II 一.有优先级的if语句 if..else if.. else i ...

  5. NC参照查那个表

    select * from bd_refinfo where name like '%人员工作记录全职树(行政树)%';select * from bd_refinfo where name like ...

  6. Activiti源码分析(框架、核心类。。。)

    http://jiangwenfeng762.iteye.com/blog/1338553 Activiti是业界很流行的java工作流引擎,关于Activiti与JBPM5的关系和如何选择不是本文要 ...

  7. UrlOfFIle

    如上,报错位置为folder.Files[],表示这里需要的是文件的Url地址,即folder.Files[文件的Url地址].

  8. C#.net在后台执行javascript

    string script = string.Format("<script type='text/javascript' >alert('{0}');</script&g ...

  9. Android之Http网络编程(二)

    上一篇文章简单的介绍了Android中http的两种通信方式,并且分别用获取百度网页做了实例.但是在实际应用中,更多的是客户端通过请求的参数来实现在服务端的具体操作,并最终返回数据给客户端.因为我们不 ...

  10. ###STL学习--迭代器

    点击查看Evernote原文. #@author: gr #@date: 2014-08-23 #@email: forgerui@gmail.com STL中的迭代器. ###stl学习 |--迭代 ...