Skip to content

Commit 4244908

Browse files
committed
Greedy
1 parent 45104f4 commit 4244908

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include<bits/stdc++.h>
2+
#define ll long long
3+
using namespace std;
4+
5+
6+
int main(){
7+
int t;
8+
cin>>t;
9+
while(t--){
10+
int n;
11+
cin>>n;
12+
vector<ll>arr(n);
13+
cin>>arr[0];
14+
ll sum = 0;
15+
for(int i=1;i<n;i++){
16+
cin>>arr[i];
17+
sum += max(arr[i],arr[i-1]);
18+
}
19+
cout<<sum<<endl;
20+
}
21+
}

0 commit comments

Comments
 (0)