結果

問題 No.1416 ショッピングモール
ユーザー harurun
提出日時 2020-12-17 13:07:25
言語 Java
(openjdk 23)
結果
AC  
実行時間 375 ms / 1,000 ms
コード長 588 bytes
コンパイル時間 2,932 ms
コンパイル使用メモリ 76,808 KB
実行使用メモリ 48,752 KB
最終ジャッジ日時 2024-09-20 06:59:07
合計ジャッジ時間 7,155 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    int n,ans=0,cnt=0,N,a=1;
    n=Integer.parseInt(scan.next());
    N=n;
    Integer[] A=new Integer[n];
    for(int i=0;i<n;i++)A[i]=Integer.parseInt(scan.next());
    Arrays.sort(A,Collections.reverseOrder());
    for(int i=0;i<17;i++){
      a=Math.min(a,N);
      for(int j=0;j<a;j++){
        ans+=i*A[cnt++];
      }
      N-=a;
      a*=2;
      if(N<=0)break;
    }
    System.out.println(ans);
  }
}

0