Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
q
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
#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; } }
g++
7 1 2 3 4 5 6 7
Show compiler warnings
[
+
] Compiler args
[
-
]
Show input
Compilation time: 1.63 sec, absolute running time: 0.17 sec, cpu time: 0.01 sec, memory peak: 3 Mb, absolute service time: 1,87 sec
edit mode
|
history
|
discussion
2