結果

問題 No.2008 Super Worker
ユーザー tenten
提出日時 2022-07-20 08:40:51
言語 Java
(openjdk 23)
結果
AC  
実行時間 868 ms / 2,000 ms
コード長 1,920 bytes
コンパイル時間 3,725 ms
コンパイル使用メモリ 78,332 KB
実行使用メモリ 60,936 KB
最終ジャッジ日時 2024-07-02 12:07:37
合計ジャッジ時間 15,717 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    static final int MOD = 1000000007;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        Work[] works = new Work[n];
        for (int i = 0; i < n; i++) {
            works[i] = new Work(sc.nextInt());
        }
        for (int i = 0; i < n; i++) {
            works[i].b = sc.nextInt();
        }
        Arrays.sort(works);
        long base = 1;
        long income = 0;
        for (Work x : works) {
            income += x.a * base % MOD;
            income %= MOD;
            base *= x.b;
            base %= MOD;
        }
        System.out.println(income);
    }
    
    static class Work implements Comparable<Work> {
        long a;
        long b;
        
        public Work(long a) {
            this.a = a;
        }
        
        public int compareTo(Work another) {
            long left = a + b * another.a;
            long right = another.a + another.b * a;
            if (left == right) {
                return 0;
            } else if (left < right) {
                return 1;
            } else {
                return -1;
            }
        }
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0