forked from thegauravparmar/CodingNinjasRound2Solution
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrid_path.cpp
52 lines (52 loc) · 983 Bytes
/
grid_path.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
52
#include<bits/stdc++.h>
#define M 100
using namespace std;
int main()
{
unsigned long long int a[M][2];
const unsigned int m=1000000007;
int n=0;
cin>>n;
int first=0;
int second=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<2;j++)
{
cin>>a[i][j] ;
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<2;j++)
{
a[i][j]=a[i][j]%m ;
}
}
first=a[0][0];
int temp=a[0][0];
for(int i=1;i<n;i++)
{
int t=max(a[i][0],a[i][1]);
if(t>temp)
{
first+=t;
temp=t;
}
}
temp=a[0][1];
for(int i=1;i<n;i++)
{
int t=max(a[i][0],a[i][1]);
if(t>temp)
{
second+=t;
temp=t;
}
}
if(first>second)
cout<<first;
else
cout<<second;
return 0;
}