Md_Sakib_Hossain

Codeforces Contest Dev - 2

Oct 3rd, 2021 (edited)
951
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.63 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package codeforces;
  7.  
  8. import java.text.NumberFormat;
  9. import java.util.Locale;
  10. import java.io.BufferedReader;
  11. import java.io.IOException;
  12. import java.io.InputStreamReader;
  13. import java.util.StringTokenizer;
  14.  
  15.  
  16.  
  17.  
  18.  
  19. public class Codeforces {
  20.         public static FastReader fast = new FastReader();
  21.  
  22.    
  23.     public static void DoOperation(int n, int H){
  24.         int Max=0,Max2=0, count=0;
  25.         boolean Val = true;
  26.         int a[] = new int[n];
  27.         for(int i=0; i<n;i++){
  28.           a[i] = fast.nextInt();
  29.         }
  30.         for(int i=0; i<n;i++){
  31.           if(a[i]>Max)
  32.               Max = a[i];
  33.         }
  34.         for(int i=0;i<n;i++){
  35.             if(Max>a[i] && a[i]>Max2)
  36.                Max2=a[i];
  37.         }
  38.        
  39.         for(;0<=H;){
  40.             if(Val){
  41.                 H-=Max;
  42.                 Val=false;
  43.                 count++;
  44.             }else{
  45.                 H-=Max2;
  46.                 Val=true;
  47.                 count++;
  48.             }
  49.         }
  50.  
  51.         System.out.println(count);
  52.        
  53.     }
  54.    
  55.  
  56.     public static void main(String[] args) {
  57.        
  58.         int t,n,i,H;
  59.         t = fast.nextInt();
  60.         for(i=0;i<t;i++){
  61.             n = fast.nextInt();
  62.             H = fast.nextInt();
  63.             DoOperation(n,H);
  64.         }
  65.        
  66.        
  67.        
  68.        
  69.        
  70.        
  71.      }
  72.  
  73.     private static class FastReader {
  74.         BufferedReader br;
  75.         StringTokenizer st;
  76.  
  77.         public FastReader() {
  78.             br = new BufferedReader(new InputStreamReader(System.in));
  79.         }
  80.         String next()
  81.         {
  82.             while (st == null || !st.hasMoreElements()) {
  83.                 try {
  84.                     st = new StringTokenizer(br.readLine());
  85.                 }
  86.                 catch (IOException e) {
  87.                     e.printStackTrace();
  88.                 }
  89.             }
  90.             return st.nextToken();
  91.         }
  92.  
  93.         int nextInt() { return Integer.parseInt(next()); } // For int
  94.  
  95.         long nextLong() { return Long.parseLong(next()); } // for long
  96.  
  97.         double nextDouble(){ return Double.parseDouble(next()); }
  98.  
  99.         String nextLine()                                 // for string
  100.         {
  101.             String str = "";
  102.             try {
  103.                 str = br.readLine();
  104.             }
  105.             catch (IOException e) {
  106.                 e.printStackTrace();
  107.             }
  108.             return str;
  109.         }
  110.     }
  111.  
  112.  
  113.    
  114. }
Add Comment
Please, Sign In to add comment