Skip to content

Commit cd58a3f

Browse files
committed
usaco silver berry picking
1 parent 8bf4bd6 commit cd58a3f

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

.clang-tidy

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
Checks: '-*,clang-diagnostic-*,-clang-diagnostic-unused-value,clang-analyzer-*,bugprone-*,performance-*,'
2+
Checks: '-*,clang-diagnostic-*,-clang-diagnostic-unused-value,clang-analyzer-*,bugprone-*,performance-*,-bugprone-macro-parentheses'
33
HeaderFilterRegex: ''
44
WarningsAsErrors: '*'
55
AnalyzeTemporaryDtors: false

usaco/berry_picking.cpp

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* @author : Naowal Rahman
3+
* @created : 07/04/2022 04:07:44 PM
4+
* @filename : berry_picking
5+
*/
6+
7+
#include <bits/stdc++.h>
8+
using namespace std;
9+
#define vi vector<int>
10+
#define FOR(i, s, e) for(int i = s; i < e; i++)
11+
#define FORE(i, s, e) for(int i = s; i <= e; i++)
12+
13+
int main() {
14+
ios::sync_with_stdio(false);
15+
cin.tie(nullptr);
16+
17+
ifstream cin("berries.in");
18+
ofstream cout("berries.out");
19+
20+
int n, k; cin >> n >> k;
21+
int A[1001];
22+
int mx = 0;
23+
FOR(i, 0, n) {
24+
cin >> A[i];
25+
mx = max(mx, A[i]);
26+
}
27+
28+
int best = 0;
29+
FOR(q, 1, mx) {
30+
int chunks[1001] = {0};
31+
FOR(i, 0, n) {
32+
chunks[q] += A[i] / q;
33+
chunks[A[i]%q]++;
34+
}
35+
36+
if(k/2 > chunks[q]) continue;
37+
chunks[q] -= k/2;
38+
39+
int given = 0, currc = q, total = 0;
40+
while(currc > 0 && given < k/2) {
41+
if(chunks[currc] > 0) {
42+
given++;
43+
total += currc;
44+
chunks[currc]--;
45+
}
46+
else currc--;
47+
}
48+
49+
if(given == k/2) {
50+
best = max(best, total);
51+
}
52+
}
53+
54+
cout << best;
55+
56+
return 0;
57+
}
58+

0 commit comments

Comments
 (0)