在第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读取一个文件并打印到控制台上

    package test9; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundExcept ...

  2. js内置对象处理-打印学生成绩单

    效果图: 任务: 1.通过js的内置对象得到当前日期 var date=new Date(); var year=date.toString().slice(11,15); document.writ ...

  3. C# 接口的隐式与显示实现【转】

    以前在用到接口时,从来没注意到接口分为隐式实现与显示实现.昨天在浏览博客时看到相关内容,现在根据自己的理解记录一下,方便日后碰到的时候温习温习.通俗的来讲,“显示接口实现”就是使用接口名称作为方法名的 ...

  4. zabbix数据存储

    一.zabbix数据库 zabbix-server将采集到的数据存储在数据库中,最常用的Mysql,数据存储的大小和每秒处理的数据量有关,数据存储取决于每秒处理的数据量和Housekeeper的删除数 ...

  5. ios常用的一些类库

    在网上收集到的 一:第三方插件 1:基于响应式编程思想的oc 地址:https://github.com/ReactiveCocoa/ReactiveCocoa 2:hud提示框 地址:https:/ ...

  6. 关于Masonry框架(AutoLayout)的用法--面向初学者

    Masonry作为目前较为流行的自动布局第三方框架,简单易用,大大减少了程序员花在UI布局和屏幕适配的精力与时间. 1 基本用法 1.1 事例1: 图1-1 // 首先是view1自动布局 [view ...

  7. mina2.0 spring

    Apache MINA是一个网络应用程序框架,它可以帮助用户开发的高性能.高扩展性的网络应用程序.它提供了一个抽象的事件驱动的异步API在不同传输如TCP/IP和UDP/IP通过java NIO. A ...

  8. hibernate案例 测试代码

    测试staff数据表连接到maeclipse 在staff中插入一行 package com.hibernate.test; import org.hibernate.Session; import ...

  9. 【制作镜像Win*】系统安装

    图形化安装系统,在询问“进行何种类型的安装?”时,选择“自定义(高级)” 下一步看不到硬盘,如图: 选择“加载驱动程序”,安装驱动. 将相应版本的netkvm.inf和viostor.inf装上. 继 ...

  10. Config spec rules for elements in subbranches

    Quote from:  Config spec rules for elements in subbranches The following is an example of a config s ...