728x90
package Greedy;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;
public class PartTimeSecurity {
static int n,m;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
n = Integer.parseInt(br.readLine());
Long[] arr = new Long[n];
for(int i=0; i<n; i++){
arr[i]= Long.parseLong(br.readLine());
}
Arrays.sort(arr, Collections.reverseOrder());
Long total =0L;//더했을 때 꼭 주의하기!-> Long 형이 될 수 있다.
for(int i=1; i<=n; i++){
Long tip = arr[i-1]-(i-1);
if(tip<0){continue;}
total = total + tip;
}
System.out.println(total);
}
}
- Long 형 따지는거 이제 안틀릴 때쯤 됐는데 계속 틀린다.. ㅋㅋ