-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproblem60.cpp
More file actions
78 lines (65 loc) · 1.91 KB
/
problem60.cpp
File metadata and controls
78 lines (65 loc) · 1.91 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class SpellInput {
public:
int n, m;
vector<long long> merlin, morgana;
void readInput() {
cout << "Enter number of Merlin's spells: ";
cin >> n;
merlin.resize(n);
cout << "Enter Merlin's spell powers: ";
for (int i = 0; i < n; ++i) cin >> merlin[i];
cout << "Enter number of Morgana's spells: ";
cin >> m;
morgana.resize(m);
cout << "Enter Morgana's spell powers: ";
for (int i = 0; i < m; ++i) cin >> morgana[i];
}
bool isValidRange() {
return (n >= 1 && n <= 1e5 && m >= 1 && m <= 1e5);
}
bool isValidSpells() {
for (long long x : merlin)
if (x < 0 || x > 1e9) return false;
for (long long x : morgana)
if (x < 0 || x > 1e9) return false;
return true;
}
};
class DuelPreparation {
public:
static long long calculateMana(const vector<long long>& merlin, const vector<long long>& morgana) {
long long strongest = *max_element(morgana.begin(), morgana.end());
long long minPower = strongest + 1;
long long totalMana = 0;
for (long long power : merlin) {
if (power < minPower)
totalMana += (minPower - power);
}
return totalMana;
}
};
class ManaPrinter {
public:
static void print(long long mana) {
cout << "Minimum mana required: " << mana << endl;
}
};
int main() {
SpellInput input;
input.readInput();
if (!input.isValidRange()) {
cout << "Number of spells must be in range [1, 1e5]." << endl;
return 1;
}
if (!input.isValidSpells()) {
cout << "Enter Spell power within the range [0, 1e9]." << endl;
return 1;
}
long long mana = DuelPreparation::calculateMana(input.merlin, input.morgana);
ManaPrinter::print(mana);
return 0;
}