PKU_ACM_3627_Bookshelf

 http://acm.pku.edu.cn/JudgeOnline/problem?id=3627 原题

 

简单题

 

  1. import java.io.*;
  2. import java.util.*;
  3. import java.math.*;
  4. public class Main
  5. {
  6.     static int[] bookHeight;
  7.     static int n;
  8.     static BigInteger b;
  9.     public static void main(String[] args) throws Exception
  10.     {
  11.         readFile();
  12.     }   
  13.     public static void readFile() throws Exception
  14.     {
  15.         BufferedReader br = new BufferedReader(
  16.             new InputStreamReader(System.in));
  17.         StringTokenizer st = new StringTokenizer(
  18.             br.readLine()," ");
  19.         n = Integer.valueOf(st.nextToken());
  20.         b = new BigInteger(st.nextToken());
  21.         int iCount = 0;
  22.         bookHeight = new int[n];
  23.         while(iCount<n)
  24.         {
  25.             bookHeight[iCount++] = Integer.valueOf(
  26.                 br.readLine()); 
  27.         }
  28.         process();
  29.     }
  30.     public static void defbug()
  31.     {
  32.         for(int i=0; i<bookHeight.length; i++)
  33.             System.out.println(bookHeight[i]+" ");
  34.         System.out.println();
  35.     }
  36.     public static void process()
  37.     {
  38.         Arrays.sort(bookHeight);
  39.         BigInteger sum = BigInteger.valueOf(0L);
  40.         BigInteger temp;
  41.         int iCount = 0;
  42.         for(int i=bookHeight.length-1; i>=0; i--)
  43.         {
  44.             sum = sum.add(BigInteger.valueOf(
  45.                     (long)(bookHeight[i])));
  46.             temp = sum.max(b);
  47.             iCount++;
  48.             if(temp.equals(sum))
  49.                 break;  
  50.         }
  51.         System.out.print(iCount);
  52.     }
  53. }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值