-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfridge.cpp
More file actions
48 lines (44 loc) · 897 Bytes
/
fridge.cpp
File metadata and controls
48 lines (44 loc) · 897 Bytes
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
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <climits>
#define YES true
#define NO false
using namespace std;
int *food, n;
bool isAllRot() {
for (int i = 0; i < n; ++i) {
if (food[i] == 0) {
return YES;
}
}
return NO;
}
void calculateMin(int &min, int &minIndex) {
for (int i = 0; i < n; ++i) {
if (food[i] < min) {
min = food[i];
minIndex = i;
}
}
}
int main() {
scanf("%d",&n);
food = new int[n];
for (int i = 0; i < n; ++i) {
scanf("%d",&food[i]);
}
int minIndex = 0;
int min = INT_MAX;
int countDay = 0;
while (!isAllRot()) {
calculateMin(min, minIndex);
for (int i = 0; i < n; ++i) {
if (i != minIndex) {
--food[i];
}
}
++countDay;
}
printf("%d",countDay);
}