Codeforces673回合區域二第一題
Copy-paste
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
— Hey folks, how do you like this problem?
— That’ll do it.
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
Note
In the first test case we get either a=[1,2] or a=[2,1] after casting the spell for the first time, and it is impossible to cast it again.
理論上這應該算一個入門級的貪心題目……確實挺簡單的。
#include <iostream>
#include <algorithm>
using namespace std;
int candies[2000];
int main()
{
int T;
int i, j;
cin >> T;
while (T--)
{
int ans = 0;
int n, k;
cin >> n >> k;
for (i = 1; i <= n; i++)
cin >> candies[i];
sort(candies + 1, candies + i);
j = 0;
for (i = 2; i <= n; i++)
{
if (k > candies[i])
ans += (k - candies[i]) / candies[1];
}
cout << ans << endl;
}
}
相關文章
- JVM(二)-記憶體區域之執行緒私有區域JVM記憶體執行緒
- [Leetcode]303.區域和檢索&&304.二維區域和檢索LeetCode
- JVM系列(二) - JVM記憶體區域JVM記憶體
- 2019 面試實戰 - 第一回合面試
- 2018 ICPC南京區域賽題解 更新至 8 題
- 區塊鏈的應用領域—物聯網和物流領域(二)區塊鏈
- OSPF單區域和多區域
- 2019 面試實戰 - 第二回合面試
- Python閉包區域性變數問題Python變數
- 搭建你的第一個區塊鏈網路(二)區塊鏈
- 區塊鏈通識問題(二)區塊鏈
- 認證領域所存在的問題和區塊鏈防偽系統解決方案(二)區塊鏈
- App 多區域皮膚(主題)的實現APP
- 萬萬沒想到一個普通的地區問題,竟然讓我們大戰了300回合
- 區域網與廣域網
- 二次開發連線區域網其它資料庫資料庫
- 如何優雅地從 C++ 向量中提取二維矩形區域C++
- Python實戰操作:解題之被圍繞的區域Python
- hdu--4455+ Substrings+2012杭州區域賽C題+DP
- LeetCode刷題記112-130. 被圍繞的區域LeetCode
- Excel如何設定列印區域?Exce列印區域設定教程Excel
- 區域(Region)和可用區(Availability Zone)AI
- 定義基因區域
- 區域網的管理
- Facebook 小遊戲 google play 商店這個區域分配問題遊戲Go
- visual studio IDE 17.10版本 摺疊區域高亮問題IDE
- 手機端區域性滾動問題 overflow-y:auto
- 題解:P9788 [ROIR 2020 Day2] 區域規劃
- 劍指 offer 第一題: 二維陣列中的查詢陣列
- 【目標區域捕獲-2】目標區域捕獲簡介
- QTableView表格控制元件區域選擇-自繪選擇區域QTView控制元件
- JVM——記憶體區域:執行時資料區域詳解JVM記憶體
- 如何解決移動端的安全區域為0的問題
- 跨域問題(普通跨域和springsecurity跨域)跨域SpringGse
- Java™ 教程(區域性類)Java
- JVM 記憶體區域JVM記憶體
- 【JVM記憶體區域】JVM記憶體
- 元件無線區域網元件