-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3020.cpp
More file actions
40 lines (40 loc) · 1.03 KB
/
3020.cpp
File metadata and controls
40 lines (40 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
vector<int> v1;
vector<int> v2;
int main(){
ios::sync_with_stdio(0); cin.tie(0);
int N, H; cin>>N>>H;
vector<int> res(H+1);
for(int i=0; i<N; ++i){
int a; cin>>a;
if(i%2==0){
v1.push_back(a);
} else {
v2.push_back(a);
}
}
sort(v1.begin(), v1.end());
sort(v2.begin(), v2.end());
int l=0, r=1;
int minVal = 987654321;
int cnt=0;
int idx=0;
for(int h=1; h<=H; ++h){
while(idx < v1.size() && v1[idx]<h) idx++;
res[h]=v1.size()-idx;
// cout << "res["<<h<<"]="<<res[h]<<'\n';
}
idx=0;
for(int h=1; h<=H; ++h){
while(idx < v2.size() && v2[idx]<h) idx++;
int resIdx = H-h+1;
res[resIdx]+=v2.size()-idx;
// cout << "res["<<resIdx<<"]="<<res[resIdx]<<'\n';
if(minVal>res[resIdx]) minVal = res[resIdx], cnt=1;
else if(minVal==res[resIdx]) cnt++;
}
cout << minVal << " " << cnt << '\n';
}