题解 | #小鸡啄米#

小鸡啄米

https://www.nowcoder.com/practice/c2a7f39bd97547eb9a1263d624af4cb3

import java.util.Arrays;
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        long[] riceList = new long[num];
        for (int i = 0; i < num; i++) {
            riceList[i] = scanner.nextLong();
        }
        Arrays.sort(riceList);
        long local = 0;
        long total = 0;
        for (int i = num - 1; i >= 0; i--) {
            local += riceList[i];
            total += local;
        }
        System.out.println(total);
    }
}

全部评论

相关推荐

云边有个小卖铺儿:校招生违约率低,所以我要高😂
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务