AOJ 1018
・問題リンク Cheating on ICPC
・コメント
しばらくの間REをずっとくらっていて、なかなかアクセプトできませんでしたが、tempというのを加えて考えなおすことで上手くいきました。
・ソース
import java.util.Scanner; import java.util.ArrayList; import java.util.Collections; public class P1018 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int n = sc.nextInt(); ArrayList<Long> list = new ArrayList<Long>(); for (int i = 0; i < n; i++) { list.add(sc.nextLong()); } Collections.sort(list);// ソート long[] a = new long[n + 1]; for (int i = 0; i < list.size(); i++) { a[i] = list.get(i); } long ans = a[0]; long temp = a[0]; for (int i = 1; i < a.length-1; i++) { ans += (a[i] += temp); temp = a[i]; } System.out.println(ans); } } }