#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;
int main(){
cin.tie(0)->sync_with_stdio(0);
int n;
cin >> n;
map<int,int> mp;
for(int i=0;i<n;i++){
int x;
cin >> x;
mp[x]++;
}
int last=-1;//上一个数
int cost=0;//上一个数的数量
int ans=0;//结果
for(auto x:mp){
if(x.first==last+1){
//这个数比前面一个数大1,则结果加上这个数的数量-前一个数的数量
ans+=max(x.second-cost,0);
}
else{
//否则直接加上这个数的数量
ans+=x.second;
}
last=x.first;
cost=x.second;
}
cout << ans << '\n';
}
今天的每日一题还是很简单的喵~



京公网安备 11010502036488号