-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProblem_1465_maxArea.cc
53 lines (47 loc) · 1.03 KB
/
Problem_1465_maxArea.cc
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
#include <algorithm>
#include <iostream>
#include <vector>
#include "UnitTest.h"
using namespace std;
class Solution
{
private:
int getMax(vector<int>& arr, int last)
{
int ans = 0;
int pre = 0;
for (auto& i : arr)
{
ans = std::max(i - pre, ans);
pre = i;
}
return std::max(ans, last - pre);
}
public:
int maxArea(int h, int w, vector<int>& horizontalCuts, vector<int>& verticalCuts)
{
static const int mod = 1e9 + 7;
std::sort(horizontalCuts.begin(), horizontalCuts.end());
std::sort(verticalCuts.begin(), verticalCuts.end());
return (long long) getMax(horizontalCuts, h) * getMax(verticalCuts, w) % mod;
}
};
void test()
{
Solution s;
vector<int> h1 = {1, 2, 4};
vector<int> v1 = {1, 3};
vector<int> h2 = {3, 1};
vector<int> v2 = {1};
vector<int> h3 = {3};
vector<int> v3 = {3};
EXPECT_EQ_INT(4, s.maxArea(5, 4, h1, v1));
EXPECT_EQ_INT(6, s.maxArea(5, 4, h2, v2));
EXPECT_EQ_INT(9, s.maxArea(5, 4, h3, v3));
EXPECT_SUMMARY;
}
int main()
{
test();
return 0;
}