Submission
Status:
[PPP][PPP][PPP][PPP][PPP]
Subtask/Task Score:
{20/20}{20/20}{20/20}{20/20}{20/20}
Score: 100
User: Nitro_Legacy
Problemset: สมดุลย์ชีวิต
Language: cpp
Time: 0.013 second
Submitted On: 2026-05-09 14:07:05
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
ll n;
cin>>n;
vector<ll> work(n);
vector<ll> high;
vector<ll> low;
for (ll i = 0; i < n; i++){
cin>>work[i];
if (work[i] > 18){
high.push_back(work[i]);
} else {
low.push_back(work[i]);
}
}
if (low.size() >= high.size()){
cout << 2 * high.size() + low.size() - high.size();
} else {
cout<< 2 * low.size() + 2 * (high.size() - low.size()) - 1;
}
return 0;
}
//put the data into two vectors: 1 for 18 and less, the other for more than 18.
//5, 7, 19, 20, 1, 18, 2 --> 20 1 19 2 18 5 7.
// two cases: 1) if 18- >= 18+ --> 2*min(18+, 18-) + abs(18+ - (18-))
// 2) if 18+ > 18- --> 2*min(18+, 18-) + 2*(18+ - 18- )-1