728x90
1758번: 알바생 강호
첫째 줄에 스타박스 앞에 서 있는 사람의 수 N이 주어진다. N은 100,000보다 작은 자연수이다. 둘째 줄부터 총 N개의 줄에 각 사람이 주려고 하는 팁이 주어진다. 팁은 100,000보다 작거나 같은 자연수
www.acmicpc.net
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 형 따지는거 이제 안틀릴 때쯤 됐는데 계속 틀린다.. ㅋㅋ