Skip to content

Instantly share code, notes, and snippets.

@joaogui1
Created May 17, 2016 01:32
Show Gist options
  • Save joaogui1/4fb01c7a7a72ced06aff5678c79ae4ff to your computer and use it in GitHub Desktop.
Save joaogui1/4fb01c7a7a72ced06aff5678c79ae4ff to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
#define MAXN 1000100
set<int> s;
int altura[MAXN],cont[MAXN];
int n,ans;
int main(){
scanf("%d", &n);
for(int i = 0; i < n; i++){
scanf("%d", &altura[i]);
cont[altura[i]]++;
s.insert(altura[i]);
}
set<int>::iterator it;
for(int i = 0; i < n; i++){
if(cont[altura[i]] != 0){
int x = altura[i];
ans++;
cont[x]--;
while(true){
x--;
it = s.find(x);
if(it != s.end() && cont[x] > 0)
cont[x]--;
else break;
}
}
}
printf("%d\n",ans);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment