#include <iostream>
#include <vector>
#include <array>
using namespace std;
void scan(vector<int>&, int&);
void output(int);
int find_maximum_element(vector<int>&);
int calculate_number_of_arrows(vector<int>&, const int);
int calculate_counter_arrows(vector<int>&);
int main() {
vector<int> heights;
int size;
scan(heights, size);
output(calculate_number_of_arrows(heights, size));
}
int calculate_number_of_arrows(vector<int>& heights, const int size) {
vector<int> histogtam(find_maximum_element(heights) + 2);
for (int height : heights) {
if (histogtam[height + 1] > 0){
histogtam[height]++;
histogtam[height + 1]--;
} else {
histogtam[height]++;
}
}
return calculate_counter_arrows(histogtam);
}
int calculate_counter_arrows(vector<int>& histogram){
int counter = 0;
for (int item: histogram)
counter += item;
return counter;
}
int find_maximum_element(vector<int>& heights) {
int max = -1;
for(int height : heights) {
if (height > max) {
max = height;
}
}
return max;
}
void output(int sum) {
cout << sum;
}
void scan(vector<int>& heights, int& size){
cin >> size;
for (int counter = 0; counter < size; counter++) {
int temp;
cin >> temp;
heights.push_back(temp);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
436 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
114 ms |
8124 KB |
Output is correct |
6 |
Correct |
119 ms |
8640 KB |
Output is correct |
7 |
Correct |
113 ms |
8384 KB |
Output is correct |
8 |
Correct |
93 ms |
8388 KB |
Output is correct |
9 |
Correct |
116 ms |
7612 KB |
Output is correct |
10 |
Correct |
104 ms |
8128 KB |
Output is correct |