-
Notifications
You must be signed in to change notification settings - Fork 0
/
leet2017.cpp
51 lines (48 loc) · 1.06 KB
/
leet2017.cpp
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
#include <stdio.h>
#include <string.h>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <functional>
#include <cmath>
#include <set>
#include <map>
#include <assert.h>
#include <stack>
#include <unordered_map>
using namespace std;
using namespace std;
class Solution {
public:
long long gridGame(vector<vector<int>>& grid) {
int N = grid[0].size();
vector<long long> up(N);
vector<long long> down(N);
up[0] = grid[0][0];
down[0] = grid[1][0];
for(int i=1;i<N;i++)
{
up[i] = up[i-1]+grid[0][i];
down[i] = down[i-1]+grid[1][i];
}
long long re = min(up[N-1]-up[0],down[N-2]);
for(int i=1;i<N-1;i++)
{
long long temp = max(down[i-1],up[N-1]-up[i]);
re = min(re,temp);
}
return re;
}
};
int main()
{
vector<vector<int>> grid = {{3,3,1},{8,5,2}};
Solution sol;
int x = sol.gridGame(grid);
return 0;
}