Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package codeforces;
- import java.text.NumberFormat;
- import java.util.Locale;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.StringTokenizer;
- public class Codeforces {
- public static FastReader fast = new FastReader();
- public static void DoOperation(int n, int H){
- int Max=0,Max2=0, count=0;
- boolean Val = true;
- int a[] = new int[n];
- for(int i=0; i<n;i++){
- a[i] = fast.nextInt();
- }
- for(int i=0; i<n;i++){
- if(a[i]>Max)
- Max = a[i];
- }
- for(int i=0;i<n;i++){
- if(Max>a[i] && a[i]>Max2)
- Max2=a[i];
- }
- for(;0<=H;){
- if(Val){
- H-=Max;
- Val=false;
- count++;
- }else{
- H-=Max2;
- Val=true;
- count++;
- }
- }
- System.out.println(count);
- }
- public static void main(String[] args) {
- int t,n,i,H;
- t = fast.nextInt();
- for(i=0;i<t;i++){
- n = fast.nextInt();
- H = fast.nextInt();
- DoOperation(n,H);
- }
- }
- private static class FastReader {
- BufferedReader br;
- StringTokenizer st;
- public FastReader() {
- br = new BufferedReader(new InputStreamReader(System.in));
- }
- String next()
- {
- while (st == null || !st.hasMoreElements()) {
- try {
- st = new StringTokenizer(br.readLine());
- }
- catch (IOException e) {
- e.printStackTrace();
- }
- }
- return st.nextToken();
- }
- int nextInt() { return Integer.parseInt(next()); } // For int
- long nextLong() { return Long.parseLong(next()); } // for long
- double nextDouble(){ return Double.parseDouble(next()); }
- String nextLine() // for string
- {
- String str = "";
- try {
- str = br.readLine();
- }
- catch (IOException e) {
- e.printStackTrace();
- }
- return str;
- }
- }
- }
Add Comment
Please, Sign In to add comment