https://www.acmicpc.net/problem/16678
처음 시행 될 때를 생각해야 되기 때문에 t는 1.
arr[i]가 t보다 크거나 같으면, 그 수 만큼 해커가 있어야 다시 시행 가능.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include <iostream> #include <algorithm> using namespace std; int main(){ int arr[100000]; int n,t=1; long ans = 0; cin >> n; for(int i = 0; i < n; i++) cin >> arr[i]; sort(arr,arr+n); for(int i = 0; i < n; i++){ if(arr[i] >= t){ ans+=arr[i]-t; t++; } } cout << ans; } | cs |
반응형
'프로그래밍 > 문제풀이' 카테고리의 다른 글
[dp] 백준 2579 계단오르기 (0) | 2019.02.02 |
---|---|
[etc] 백준 10757 큰 수 A+B (0) | 2019.01.29 |
[etc] 백준 16676 근우의 다이어리 꾸미기 (0) | 2019.01.24 |
[etc] 백준 16674 2018년을 되돌아보며 (0) | 2019.01.22 |
[bfs] 백준 16569 화산쇄설류 (0) | 2019.01.17 |