在第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. 如何在Xilinx ISE中使用TCL提高工作效率

    http://wenku.baidu.com/link?url=jxtsPLGUlWwYuD8TtfWYYU_NhY5Qty3rx8ZDLCkINLe39JRGb90V5HoJhnkn9r_PQ6vZ ...

  3. ASP.NET MVC总结

    一.概述 1.单元测试的NUnit, MBUnit, MSTest, XUnit以及其他的框架 2.ASP.NET MVC 应用的默认目录结构有三个顶层目录: Controllers.Models.V ...

  4. xxx is not in the sudoers file.This incident will be reported.的解决方法

    1.切换到root用户下,怎么切换就不用说了吧,不会的自己百度去. 2.添加sudo文件的写权限,命令是:chmod u+w /etc/sudoers 3.编辑sudoers文件vi /etc/sud ...

  5. WCF编程系列(三)地址与绑定

    WCF编程系列(三)地址与绑定   地址     地址指定了接收消息的位置,WCF中地址以统一资源标识符(URI)的形式指定.URI由通讯协议和位置路径两部分组成,如示例一中的: http://loc ...

  6. win10 删除资源管理器中的6个文件夹

    细心的朋友会发现,在Win10此电脑(计算机)中,除了我们最熟悉的磁盘外,还新增了视频.图片.文档.下载.音乐.桌面这6个文件夹.不少网友举觉得这6个文件夹其实并没什么用,想要去除删掉.那么Win10 ...

  7. C++对象模型与内存位对齐的简单分析(GNU GCC&VS2015编译器)

    以Fruit和Apple为例进行分析: Fruit和Apple的定义如下: 通过在两种编译环境下的测试(GNU GCC & VS2015),可以发现这两种编译器的对象模型是一样的,如下图所示: ...

  8. 使用qt制作简单的加法,乘法运算。

    1.首先构架qt应用项目 2.然后打开使用 Qt desinger打开 Fomr File 里的UI文件进行编辑 3.由于此程序只需点击加号,减号这两个按钮,所以设置了两个信号槽 4.然后是连接信号槽 ...

  9. 九度OJ 1505 两个链表的第一个公共结点 【数据结构】

    题目地址:http://ac.jobdu.com/problem.php?pid=1505 题目描述: 输入两个链表,找出它们的第一个公共结点. 输入: 输入可能包含多个测试样例. 对于每个测试案例, ...

  10. OpenJudge/Poj 1664 放苹果

    1.链接地址: http://bailian.openjudge.cn/practice/1664 http://poj.org/problem?id=1664 2.题目: 总时间限制: 1000ms ...