알고리즘 문제 풀이/그리디
17509 And the Winner Is... Ourselves!
가나무마
2021. 10. 29. 00:40
본 알고리즘 풀이는 Routine Study에서 진행하고 있습니다.
저를 포함한 구성원이 대부분 초보이므로, 원하시는분은 언제라도 들어오셔도 좋습니다.
문의는 댓글 바람.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
class Main {
public static void main(String[] args) throws IOException {
int numOfProplems = 11;
int[] penalties = new int[numOfProplems];
int wrongCount = 0;
BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
for (int i = 0; i < numOfProplems; i++) {
String[] line = bfr.readLine().split(" ");
penalties[i] = Integer.parseInt(line[0]);
wrongCount += Integer.parseInt(line[1]);
}
Arrays.sort(penalties);
int answer = 0;
int sum = 0;
for (int i = 0; i < numOfProplems; i++) {
sum += penalties[i];
answer += sum;
}
System.out.println(answer + wrongCount * 20);
}
}