C. Yet Another Tournament

Problem - 1783C - Codeforces

 

 思路:由题意知,每个人的获胜场次至少是i-1,如果我们的排名要不比第i个人差,那么我们至少要获胜i-1场,并且不能输第i个人,因为获胜场次相同的人具有相同的排名,假设我胜了4场,第i个人胜了6(他胜了我),如果我让他输我,那么我们两个都胜5场,但是我的排名上升了,首先我们要知道我们最多能够获胜几场(因为我们的排名超过第i名的条件是我们至少要获胜i-1场,所以我们获胜的越多排名才可能越高),然后我们看一下我们是否赢了第sum+1个人,因为第sum+1个人最少是sum,最大是sum+1,我们现在是sum,如果我们已经赢过他了,那么代表我们现在的胜场数相同,我们的排名都会上升,如果我现在没赢过他,那么他是sum+1场,那么我看一下能不能用前面胜过的一个人取替换掉这个人,如果能,那么我赢了他(因为我是替换的所以我还是sum场),他也变为sum场,我们的排名都上升

// Problem: C. Yet Another Tournament
// Contest: Codeforces - Educational Codeforces Round 141 (Rated for Div. 2)
// URL: https://codeforces.com/problemset/problem/1783/C
// Memory Limit: 256 MB
// Time Limit: 2000 ms

#include<iostream>
#include<cstring>
#include<string>
#include<sstream>
#include<bitset>
#include<deque>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<vector> 
#include<set>
#include<cstdlib>
#define fi first
#define se second
#define i128 __int128
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> PII;
typedef pair<int,pair<int,int> > PIII;
const double eps=1e-7;
const int N=5e5+7 ,M=5e5+7, INF=0x3f3f3f3f,mod=1e9+7,mod1=998244353;
const long long int llINF=0x3f3f3f3f3f3f3f3f;
inline ll read() {ll x=0,f=1;char c=getchar();while(c<'0'||c>'9') {if(c=='-') f=-1;c=getchar();}
while(c>='0'&&c<='9') {x=(ll)x*10+c-'0';c=getchar();} return x*f;}
inline void write(ll x) {if(x < 0) {putchar('-'); x = -x;}if(x >= 10) write(x / 10);putchar(x % 10 + '0');}
inline void write(ll x,char ch) {write(x);putchar(ch);}
void stin() {freopen("in_put.txt","r",stdin);freopen("my_out_put.txt","w",stdout);}
bool cmp0(int a,int b) {return a>b;}
template<typename T> T gcd(T a,T b) {return b==0?a:gcd(b,a%b);}
template<typename T> T lcm(T a,T b) {return a*b/gcd(a,b);}
void hack() {printf("\n----------------------------------\n");}

int T,hackT;
int n,m,k;
PII w[N];

void solve() {
	n=read(),m=read();
	
	for(int i=1;i<=n;i++) w[i].fi=read(),w[i].se=i;
	
	sort(w+1,w+1+n);
	
	int res=n+1;
	int sum=0;
	int maxn=0;
	for(int i=1;i<=n;i++) {
		if(m-w[i].fi>=0) {
			m-=w[i].fi;
			res--;
			sum++;
		}else {
			bool flag=false;
			for(int j=1;j<i;j++) {
				if(w[j].se==sum+1) flag=true;
				maxn=max(maxn,w[j].fi);
			}
			
			if(flag) {
				res--;
				printf("%d\n",res);
				return ;
			}
			break;
		}
	}
	
	for(int i=sum;i<=n;i++) {
		if(w[i].se==sum+1) {
			if(m+maxn-w[i].fi>=0) {
				res--;
			}
		}
	}
	
	printf("%d\n",res);
}   

int main() {
    // init();
    // stin();

    scanf("%d",&T);
    // T=1; 
    while(T--) hackT++,solve();
    
    return 0;       
}          

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值