首页 > 其他分享 >Codeforces Round #673 (Div. 2) Problem A

Codeforces Round #673 (Div. 2) Problem A

时间:2022-11-18 11:03:38浏览次数:39  
标签:BThero minn int contains 673 pile test Div Problem


今天的题。
本来打算把比赛坚持打完的,但是因为生病了,还是早点睡吧,把第一题摸了。
题面如下:
BThero is a powerful magician. He has got n piles of candies, the i-th pile initially contains ai

candies. BThero can cast a copy-paste spell as follows:

He chooses two piles (i,j)

such that 1≤i,j≤n and i≠j
.
All candies from pile i
are copied into pile j. Formally, the operation aj:=aj+ai

is performed.

BThero can cast this spell any number of times he wants to — but unfortunately, if some pile contains strictly more than k

candies, he loses his magic power. What is the maximum number of times BThero can cast the spell without losing his power?
Input

The first line contains one integer T
(1≤T≤500

) — the number of test cases.

Each test case consists of two lines:

the first line contains two integers n

and k (2≤n≤1000, 2≤k≤104
);
the second line contains n
integers a1, a2, …, an (1≤ai≤k

).

It is guaranteed that the sum of n
over all test cases does not exceed 1000, and the sum of k over all test cases does not exceed 104

.
Output

For each test case, print one integer — the maximum number of times BThero can cast the spell without losing his magic power.
Example
Input

3
2 2
1 1
3 5
1 2 3
3 7
3 2 2

Output

1
5
4

解题的思路还是很简单的,最优策略一定是用最小的值把每个其他数加到刚好小于k,这样的策略是最佳的。
证明从略,以后可能会补充。
代码如下:

#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 1005
using namespace std;
int T;
int n,k;
int a[maxn];
int minn,ind;
int ans;
int main(){
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&k);
minn=0x3f3f3f3f;
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
if(minn>a[i]){
ind=i;
minn=a[i];
}
}
ans=0;
for(int i=0;i<n;i++){
if(i!=ind){
ans+=(k-a[i])/minn;
}
}
printf("%d\n",ans);

}
return 0;
}


标签:BThero,minn,int,contains,673,pile,test,Div,Problem
From: https://blog.51cto.com/u_9368800/5867929

相关文章

  • Codeforces Round #672 (Div. 2) ProblemB
    9月25日的打卡。为什么又过了零点?因为和朋友去摸鱼了。今天讲一下昨晚比赛的第二题。题面如下:Danikurgentlyneedsrockandlever!Obviously,theeasiestwaytoge......
  • Codeforces Round #672 (Div. 2) Problem A
    今日份的题目。(指9月24日,因为比赛从晚上10点半持续到12点半)问题A是水题,题面如下(大半夜了,就不翻译了,赶着睡觉)(其他题目明天再发)Wheatleydecidedtotrytomakeatestcha......
  • SVG Line Between Divs (multi-point)
     <!doctypehtml><html><head><metacharset="utf-8"><title>SVGLineBetweenDivs(multi-point)</title><style>html,body{margin:0;padding:0;}......
  • Codeforces Round #828 (Div. 3) A~F
    A签到点击查看代码#include<bits/stdc++.h>#definelllonglongusingnamespacestd;constintN=2e5+10;intn;map<int,char>m;inta[N];chars[N];i......
  • WEB安全DIV+CSS基础
    0x001DIV+CSS介绍层叠样式表(英文全称:CascadingStyleSheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机......
  • Codeforces Round #833 (Div. 2)-B
    B题目链接:https://codeforces.com/contest/1748/problem/B Whatisthemaximumpossiblelengthadiversestring?100!10个数字每个出现10次暴力n*102下见代码#......
  • B. Diverse Substrings
    题目链接:Problem-B-Codeforces输入71727741010501100639999652345618789987887987998798输出1210121015106题目大意就是给出T个用例给出一个长度为n,只包含'0'......
  • vue3点击其他元素隐藏固定DIV
    vue3点击其他元素隐藏固定DIV显示的内容<divv-if="hSearch"ref="iscity"><div><inputclass="h-9w-full"placeholder="内容搜索..."/></div></div>元......
  • Codeforces Round #833 (Div. 2) D
    D.ConstructOR转化题意a|x=k1db|x=k2d我们考虑k1k2同样就只用让x包含a|b对于a|b的每一位我们用d的最后一位来填补然后在线的要是a|b这里有我们的x没有显然要让......
  • Codeforces Round #180 (Div. 2) 解题报告
    ​​题目链接​​A.​​SnowFootprints​​​​A-SnowFootprints​​Thestartingpositioncanbeanywherewithafootprint.Thefootprintscanbecategorized......