結果

問題 No.1724 [Cherry 3rd Tune A] Lápiz labial de Sonia
ユーザー tenten
提出日時 2021-11-01 15:24:51
言語 Java
(openjdk 23)
結果
AC  
実行時間 847 ms / 2,000 ms
コード長 1,922 bytes
コンパイル時間 2,381 ms
コンパイル使用メモリ 77,496 KB
実行使用メモリ 79,296 KB
最終ジャッジ日時 2024-10-10 04:52:03
合計ジャッジ時間 24,042 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int k = sc.nextInt();
        Cosme[] cosmes = new Cosme[n];
        for (int i = 0; i < n; i++) {
            cosmes[i] = new Cosme(i, sc.nextInt());
        }
        for (int i = 0; i < n; i++) {
            cosmes[i].b = sc.nextInt();
        }
        Arrays.sort(cosmes);
        char[] ans = new char[n];
        for (int i = 0; i < n; i++) {
            if (i < k) {
                ans[cosmes[i].idx] = 'A';
            } else {
                ans[cosmes[i].idx] = 'B';
            }
        } 
        System.out.println(ans);
    }
    
    static class Cosme implements Comparable<Cosme> {
        int idx;
        long a;
        long b;
        
        public Cosme(int idx, long a) {
            this.idx = idx;
            this.a = a;
        } 
        
        public int compareTo(Cosme another) {
            if (a - b == another.a - another.b) {
                return 0;
            } else if (a - b > another.a - another.b) {
                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 String nextLine() throws Exception {
        return br.readLine();
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0