在第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里程碑

    里程碑即Tag,是人为对提交进行的命名.这和Git的ID是否太长无关.使用任何数字版本号无论长短, 都没有使用一个直观的表意的字符串来的方便.例如:用里程碑名称"v2.1"对应软件 ...

  2. selendroid项目实战3 selendroid driver初始化失败问题

    小米4/LG手机作为测试用机,随着测试时间变长,driver初始化失败率越来越高. 分析: 1.手机原因: 从小米换到LG,刚开始问题确实减少了,但是时间一长,又出现类似问题,提示Connect re ...

  3. Apple Watch 使用体验

    交互 Apple Watch 支持以下几种交互方式: 按下 Digital Crown (数码表冠),在桌面和表盘之间切换. 长按 Digital Crown (数码表冠),启动 Siri. 双击 D ...

  4. css扁平化博客学习总结(四)content代码实现

    1.根据功能,把不同的部分写出来,方便扩展 <div class="content"><!-- 内容开始 --> <section class=&qu ...

  5. Java接口的表现形式

    一.概念理解 Java接口是一些方法特征的集合,并没有方法的具体实现,类似于电源插座,可以充不同类型的电器,但是必须适配特定的接口规范.接口是抽象化的,所以其不能被实例化的(不能有构造函数,创建对象) ...

  6. Android屏幕适配-资源文件夹命名与匹配规则

    说明:本文档目的为分析android工程res目录下的资源文件夹(drawable,values,layout等)在屏幕适配方面的限定与适配方法. 1. Res下文件夹命名方式 1. 可用的命名属性 ...

  7. C#定义自定义类型转换

    类型转换不限于单一继承链中的类型(派生类转换为基类或者基类转换为派生类),完全不相关的类型之间也能进行转换.关键在于在两个类型之间提供转型操作符. 在下面这样的情况下应该定义显式转型操作符: 在转型有 ...

  8. About 'atoi'

    在很多地方我们看到的都是:atoi 是一个 C Reference function atoi() convert a string to an integer. This function of s ...

  9. C++成员变量初始化顺序问题

    由于面试题中,考官出了一道简单的程序输出结果值的题:如下, class A { private: int n1; int n2; public: A():n2(0),n1(n2+2){} void P ...

  10. makefile-0711-168 SEVERE ERROR: Input file:

    ld: 0711-168 SEVERE ERROR: Input file: /cicm/commlib/include        Input files must be regular file ...