在第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. 关于Java中return和finally谁先执行.

    例子一: public class A { public static void main(String[] args) { System.out.print(tt()); } public stat ...

  2. JavaScript入门(10)

    一.Window对象 window对象是BOM的核心,window对象指当前的浏览器窗口 window对象方法 二.JavaScript计时器 在JavaScript中,我们可以在设定的时间间隔之后来 ...

  3. SQL访问EXCEL错误集合

    --行集函数 --1, OPENDATASOURCE 环境:WIN7,SQL 2014,OFFICE 2013 SELECT * FROM OPENDATASOURCE('Microsoft.ACE. ...

  4. ASP FSO操作文件(复制文件、重命名文件、删除文件、替换字符串)

    ASP FSO操作文件(复制文件.重命名文件.删除文件.替换字符串)FSO的意思是FileSystemObject,即文件系统对象.FSO对象模型包含在Scripting 类型库 (Scrrun.Dl ...

  5. 《JAVA核心技术卷 卷1 基础知识》

    第一卷 关键字:体系结构中立,可移植性,高性能,多线程 体系机构中立:通过解释字节码实现,优点是,让JAVA能在很多机器上运行.缺点是运行速度很慢. 可移植性:因为JAVA的基本数据类型有固定的大小. ...

  6. xadmin学习笔记(一)——编程准备

    前言 xadmin是GitHub上的开源项目,它是Django admin的超强升级版,提供了强大的插件系统,丰富的内置功能,以及无与伦比的UI主题,使管理系统的实现变得异常简单.详情请参见官方网址. ...

  7. java Springmvc ajax上传

    ajax上传方式相对于普通的form上传方式要便捷,在更多的时候都会使用ajax (简单的小示例) 1.要先去下载一个 jquery.ajaxfileupload.js(基于jquery.js上的js ...

  8. fgetc, getchar(), fscanf的问题

    1.漫谈:为什么 函数fscanf(FILE stream, const char format, ...)的 第3个参数中 总是用变量的地址 或者是用指针. 这个问题涉及到 传值 和 传指针.一般情 ...

  9. mysql innodb 数据打捞(一)innodb 页面结构特征

    如果文件系统损坏或意外删除了数据库文件,只要磁盘空间没有被覆盖,其实数据都还在磁盘的扇区中,还是可以恢复出来的,有些通用的文件恢复工具好象也可以恢复文件 ,但这里要研究的是在通用文件 恢复工具失效的时 ...

  10. 【nodemailer】 初试

    nodemailer 是什么? 简单的讲nodemailer就是用来发送邮件的.最近的一个项目需要向客户的注册邮箱发送验证连接,研究了一下. 刚开始我以为nodemailer还可以用来接收邮件,看了好 ...