프로그래밍/문제풀이
[etc] 백준 16678 모독
하용권
2019. 1. 27. 23:17
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 |
반응형