-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAngryCows.cpp
More file actions
61 lines (60 loc) · 1.16 KB
/
AngryCows.cpp
File metadata and controls
61 lines (60 loc) · 1.16 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* USACO 2016 January Contest, Bronze 2
* Created by Ziyi Tang
* Implementation
*/
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> all;
int n;
int countLeft(int now, int rad){
int left = all[now]-rad;
//cout << "left is " << right << endl;
int cont = 1;
for(int i = 0; i < now; i++){
if(all[i] >= left){
cont += (now-i-1+countLeft(i, rad+1));
break;
}
}
return cont;
}
int countRight(int now, int rad){
int right = all[now]+rad;
int cont = 1;
for(int i = n-1; i > now; i--){
if(all[i] <= right){
// cout << "pos " << i << " " << all[i] << endl;
cont += (i-now-1+countRight(i, rad+1));
break;
}
}
return cont;
}
int main(){
ifstream ifile("angry.in");
ifile >> n;
for(int i = 0; i < n; i++){
int tmp;
ifile >> tmp;
all.push_back(tmp);
}
ifile.close();
sort(all.begin(),all.end());
int maxp = 0;
for(int i = 0; i < n; i++){
int l = countLeft(i,1);
int r = countRight(i,1);
//cout << l << " " << r << endl;
maxp = max(maxp, l+r-1);
}
ofstream ofile("angry.out");
ofile << maxp << endl;
//cout << maxp << endl;
ofile.close();
return 0;
}