#include <bits/stdc++.h>
using namespace std;
#define H 1000001
int a[H], cnt[H];
int main(){
int n; cin >> n;
for(int i = 0; i < n; i++) cin >> a[i];
int ans = 0;
for(int i = n - 1; i > -1; i--){
cnt[a[i]]++;
if(cnt[a[i] - 1]) cnt[a[i] - 1]--; else ans++;
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
324 KB |
Output is correct |
5 |
Correct |
182 ms |
3296 KB |
Output is correct |
6 |
Correct |
179 ms |
3712 KB |
Output is correct |
7 |
Correct |
159 ms |
3148 KB |
Output is correct |
8 |
Correct |
149 ms |
3108 KB |
Output is correct |
9 |
Correct |
187 ms |
3260 KB |
Output is correct |
10 |
Correct |
228 ms |
3372 KB |
Output is correct |