2020-09-06 铺设道路

2020-09-06  本文已影响0人  JalorOo

https://www.luogu.com.cn/problem/P5019

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;

template<typename DataType>
DataType qmi(DataType m, int k)
{
    DataType res = 1, t = m;
    while (k)
    {
        if (k&1) res = res * t;
        t = t * t;
        k >>= 1;
    }
    return res;
}

int read(){
    int x = 0,f = 1;
    char c = getchar();
    while (c<'0'||c>'9') {
        if (c=='-') {
            f = -1;
        }
        c = getchar();
    }
    while (c>='0'&&c<='9') {
        x = x*10+c-'0';
        c = getchar();
    }
    return x*f;
}

#define fi(a,b) for(int i = a; i <= b; i++)
#define fj(a,b) for(int j = a; j >= b; j--)

struct MAP{
    int pos;
    int data;
};

void quickSort(MAP *a,int left,int right){
    int i,j;
    
    MAP temp,t;
    
    temp = a[(left+right)/2];//基准值
    
    i = left;
    j = right;
    
    while(i<=j){
        while (a[j].data > temp.data) {
            j--;
        }
        
        while (a[i].data < temp.data) {
            i++;
        }
        
        if (i<=j) {
            t = a[i];
            a[i] = a[j];
            a[j] = t;
            //继续下一步
            i++;
            j--;
        }
        
    }
    
    if(left<j)quickSort(a,left, j);//继续分治
    if(i<right)quickSort(a,i, right);//继续分治
}

int n,d[100005];
long long ans=0;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)     cin >> d[i];
    for(int i=2;i<=n;i++)     if(d[i] > d[i-1]) ans += d[i] - d[i-1];
    cout<<ans+d[1];
    return 0;
}
/*
6
4 3 2 5 3 5
============
9
*/
上一篇 下一篇

猜你喜欢

热点阅读