#include <iostream>
#include <cstdio>
#define debug(x) std::cerr << #x << "=" << x << std::endl

using namespace std;

const int MAXN = 1000005;
int n, l, r;
long long ans;
int a[MAXN];

int main()
{
	freopen("rain.in", "r", stdin);
	freopen("rain.out", "w", stdout);
	scanf("%d", &n);
	for(int i = 1; i <= n; i ++)
	{
		scanf("%d", &a[i]);
	}
	int flag = 0;
	for(int i = 1; i <= n; i ++)
	{
		if(flag == 2)
		{
			flag --;
			l = r;
			r = 0;
		}
		if(a[i] > a[i - 1] && a[i] > a[i + 1])
		{
			if(flag == 0)
			{
			    l = i;
			    flag ++;
		    }
			if(flag == 1) 
			{
				flag ++;
			    r = i;
			}
		}
		if(flag == 2)
		{
			int maxx = min(a[l], a[r]);
			for(int i = l + 1; i < r; i ++)
			{
				if(maxx - a[i] > 0)
				ans += maxx - a[i];
			}
		}
	}
	printf("%lld", ans);
	return 0;
}
测试点 #1
Accepted
得分:100
用时:6 ms
内存:252 KiB

输入文件(rain1.in

3
1 3 3
输出文件(rain1.out
0
选手输出
0

测试点 #2
Wrong Answer
得分:0
用时:5 ms
内存:252 KiB

输入文件(rain2.in

4
3 2 3 3
输出文件(rain2.out
1
选手输出
0
Special Judge 信息
Files user_out and answer differ

测试点 #3
Accepted
得分:100
用时:5 ms
内存:252 KiB

输入文件(rain3.in

4
4 2 4 3
输出文件(rain3.out
2
选手输出
2

测试点 #4
Wrong Answer
得分:0
用时:6 ms
内存:252 KiB

输入文件(rain4.in

1000
49 153 935 533 261 672 206 697 168 560 745 847 354 837 200 561 494 571 152 406 733 585 297 5 272 40 222 570 392 770 614 319
<3768 bytes omitted>
输出文件(rain4.out
487807
选手输出
208492
Special Judge 信息
Files user_out and answer differ

测试点 #5
Wrong Answer
得分:0
用时:5 ms
内存:252 KiB

输入文件(rain5.in

1000
841 478 902 907 730 65 103 947 844 544 596 946 116 994 140 434 556 958 131 933 5 328 594 387 51 479 744 189 584 723 629 13 
<3774 bytes omitted>
输出文件(rain5.out
493410
选手输出
207248
Special Judge 信息
Files user_out and answer differ

测试点 #6
Wrong Answer
得分:0
用时:309 ms
内存:4092 KiB

输入文件(rain6.in

1000000
733559521 608025631 567700906 936145353 624081713 556992491 17064745 147569505 189563666 540190987 166894256 761940883 7
<9888949 bytes omitted>
输出文件(rain6.out
499597567421444
选手输出
201699234676602
Special Judge 信息
Files user_out and answer differ

测试点 #7
Wrong Answer
得分:0
用时:312 ms
内存:4092 KiB

输入文件(rain7.in

1000000
953718300 54986646 304191666 735638078 816130121 369866885 889588169 842731984 114790813 123226927 502070030 827386192 7
<9889005 bytes omitted>
输出文件(rain7.out
499675611224705
选手输出
201298368996068
Special Judge 信息
Files user_out and answer differ

测试点 #8
Wrong Answer
得分:0
用时:341 ms
内存:4220 KiB

输入文件(rain8.in

1000000
62821166 49574647 721516535 41308460 878072287 175102004 698032698 776791695 302257021 145143385 255174732 451235902 381
<9888637 bytes omitted>
输出文件(rain8.out
499875366161840
选手输出
201187682128708
Special Judge 信息
Files user_out and answer differ

测试点 #9
Wrong Answer
得分:0
用时:328 ms
内存:4092 KiB

输入文件(rain9.in

1000000
694483080 721088486 321266954 171437663 527840336 259529357 536838427 699583976 565974475 249742863 942089808 396533007 
<9888363 bytes omitted>
输出文件(rain9.out
500040240311378
选手输出
201509542677837
Special Judge 信息
Files user_out and answer differ

测试点 #10
Wrong Answer
得分:0
用时:310 ms
内存:4092 KiB

输入文件(rain10.in

1000000
523878176 11190867 830003008 880064918 498395069 91379857 86465627 334448169 437031561 202642344 185872183 817157039 647
<9888842 bytes omitted>
输出文件(rain10.out
499992400538086
选手输出
201223896345367
Special Judge 信息
Files user_out and answer differ