1. 程式人生 > >NOIP2018提高組T1題解

NOIP2018提高組T1題解

題目大家可以在洛谷上看見,其實就是NOIP2013提高組的原題。 程式碼都一樣。 主要的思想是差分陣列。 程式碼如下:

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
	int ans=0,last=0; 
	int x;
	for(int i=0;i<n;i++){
		scanf("%d",&x);
		if(x>last){
			ans+=x-last;
		}
last=x; } printf("%d",ans); return 0; }