Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
q
#include<bits/stdc++.h> using namespace std; #define pb push_back int main(){ int n; cin >> n; vector <int> v; for(int i = 0;i < n;i++){ int x;cin >> x; v.pb(x); } sort(v.begin(),v.end()); vector <int> freq; int cnt = 1; for(int i = 1;i < n;i++){ if(v[i] == v[i-1]) cnt++; else { freq.pb(cnt); cnt = 1; } } freq.pb(cnt); if(freq.size() < 3) cout << 0 << endl; else{ int a = 0,b = 1,c = 2; int ans = 0; while(c < freq.size()){ while(freq[a] > 0 && freq[b] > 0 && freq[c] > 0){ freq[a]--; freq[b]--; freq[c]--; ans++; } while(c < freq.size() && (freq[a] <= 0 || freq[b] <= 0 || freq[c] <= 0)){ if(freq[a] <= 0) {a++;b++;c++;} else if(freq[b] <=0 ) {b++;c++;} else if(freq[c] <=0 ) {c++;} } } cout << ans << endl; } }
run
|
edit
|
history
|
help
0
Good morning
Programa 3 (corregido)
Shultz_Lab1.CPP
find-missing-number-arithmetic-progression
Hashing
python
133
Minimum Vertices to Traverse Directed Graph
StackQuiz
printAllPathsInMatrix