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記憶體執行緒
- JVM系列(二) - JVM記憶體區域JVM記憶體
- 2019 面試實戰 - 第一回合面試
- 區塊鏈的應用領域—物聯網和物流領域(二)區塊鏈
- [Leetcode]303.區域和檢索&&304.二維區域和檢索LeetCode
- web區域性(antd)主題方案演進Web
- 搭建你的第一個區塊鏈網路(二)區塊鏈
- 2019 面試實戰 - 第二回合面試
- 區塊鏈通識問題(二)區塊鏈
- 破解HomeWatcher v1.2 第一回合 (3千字)
- App 多區域皮膚(主題)的實現APP
- Python閉包區域性變數問題Python變數
- 認證領域所存在的問題和區塊鏈防偽系統解決方案(二)區塊鏈
- 二次開發連線區域網其它資料庫資料庫
- 如何優雅地從 C++ 向量中提取二維矩形區域C++
- Facebook 小遊戲 google play 商店這個區域分配問題遊戲Go
- Excel如何設定列印區域?Exce列印區域設定教程Excel
- JVM區域劃分JVM
- 【區域性特徵】ASIFT特徵
- NiBlack二值化演算法和區域性均值法演算法
- JVM——記憶體區域:執行時資料區域詳解JVM記憶體
- QTableView表格控制元件區域選擇-自繪選擇區域QTView控制元件
- 【目標區域捕獲-2】目標區域捕獲簡介
- Python實戰操作:解題之被圍繞的區域Python
- 手機端區域性滾動問題 overflow-y:auto
- 劍指 offer 第一題: 二維陣列中的查詢陣列
- 區域(Region)和可用區(Availability Zone)AI
- ios11 劉海屏 安全區域 適配 彈框區域適配iOS
- [深入理解Java虛擬機器]第二章 記憶體區域Java虛擬機記憶體
- 域模型之二,主要概念模型
- Java記憶體區域Java記憶體
- 【JVM記憶體區域】JVM記憶體
- Java™ 教程(區域性類)Java
- 計算機區域網計算機
- JVM 記憶體區域JVM記憶體
- JVM記憶體區域JVM記憶體
- 【OpenCV】選擇ROI區域OpenCV
- 區域網內命令大全