Submission #24366821
Source Code Expand
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ch() getchar()
#define pc(x) putchar(x)
using namespace std;
template<typename T>void read(T&x){
static char c;static int f;
for(c=ch(),f=1;c<'0'||c>'9';c=ch())if(c=='-')f=-f;
for(x=0;c>='0'&&c<='9';c=ch())x=x*10+(c&15);x*=f;
}
template<typename T>void write(T x){
static char q[65];int cnt=0;
if(x<0)pc('-'),x=-x;
q[++cnt]=x%10,x/=10;
while(x)
q[++cnt]=x%10,x/=10;
while(cnt)pc(q[cnt--]+'0');
}
const int maxn=200005;
long long A[maxn],S[maxn*2];
int main(){
int n;read(n);
for(int i=1;i<=n;++i)read(A[i]);
for(int i=n;i>=2;--i)A[i]-=A[i-1];
long long B=0,C=0;int cnt=0;
for(int i=1;i<=n;++i){
S[++cnt]=B;
S[++cnt]=-A[1]-C;
if(A[i+1]>=0)B+=A[i+1];
else C+=A[i+1];
}
sort(S+1,S+cnt+1);
long long ans=0;
for(int i=1;i<=n;++i)
ans+=S[n]-S[i];
for(int i=n+1;i<=cnt;++i)
ans+=S[i]-S[n];
write(ans),pc('\n');
return 0;
}
/*
_|_|_|_| _|_| _| _| _|_|_|_|_| _|_|_|_|_| _|
_| _| _| _| _|_| _| _| _| _|
_| _| _| _| _| _| _| _| _| _|
_| _| _|_|_|_|_| _| _| _| _| _|_|_|_|_| _|
_| _| _| _| _| _| _| _| _| _|
_| _| _| _| _| _|_| _| _| _|
_|_|_|_| _| _| _| _| _|_|_|_|_| _|_|_|_|_| _|_|_|_|_|
_|_|_|_|_| _| _| _|_|_|_| _| _|
_| _| _| _| _| _| _|
_| _| _| _| _| _| _|
_| _|_| _| _| _|_|
_| _| _| _| _| _|
_| _| _| _| _| _|
_| _| _| _|_|_|_| _|
_| _|_|_| _| _| _|_|_|_|_|
_| _| _| _| _| _|
_| _| _| _| _| _|
_| _| _| _| _| _|_|_|_|_|
_| _| _| _| _| _|
_| _| _| _|_| _|
_|_|_|_|_| _|_|_| _| _|_|_|_|_|
_|_|_|_|_| _| _| _|_|_|_|_|
_| _| _| _|
_| _| _| _|
_| _|_| _|
_| _| _|
_| _| _|
_| _| _|
Created by xiaolilsq.
*/
Submission Info
| Submission Time | |
|---|---|
| Task | D - Inc, Dec - Decomposition |
| User | xiaolilsq |
| Language | C++ (GCC 9.2.1) |
| Score | 700 |
| Code Size | 2412 Byte |
| Status | AC |
| Exec Time | 33 ms |
| Memory | 8248 KiB |
Compile Error
./Main.cpp: In function ‘void read(T&)’:
./Main.cpp:11:2: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
11 | for(x=0;c>='0'&&c<='9';c=ch())x=x*10+(c&15);x*=f;
| ^~~
./Main.cpp:11:46: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
11 | for(x=0;c>='0'&&c<='9';c=ch())x=x*10+(c&15);x*=f;
| ^
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 700 / 700 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt |
| All | 01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 02_small_01.txt, 02_small_02.txt, 02_small_03.txt, 02_small_04.txt, 02_small_05.txt, 02_small_06.txt, 02_small_07.txt, 02_small_08.txt, 02_small_09.txt, 02_small_10.txt, 03_rand_01.txt, 03_rand_02.txt, 03_rand_03.txt, 03_rand_04.txt, 03_rand_05.txt, 03_rand_06.txt, 03_rand_07.txt, 03_rand_08.txt, 03_rand_09.txt, 03_rand_10.txt, 03_rand_11.txt, 03_rand_12.txt, 03_rand_13.txt, 03_rand_14.txt, 03_rand_15.txt, 03_rand_16.txt, 03_rand_17.txt, 03_rand_18.txt, 03_rand_19.txt, 03_rand_20.txt, 04_handmade_01.txt, 04_handmade_02.txt, 04_handmade_03.txt, 04_handmade_04.txt, 04_handmade_05.txt, 04_handmade_06.txt, 04_handmade_07.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 01_sample_01.txt | AC | 11 ms | 3592 KiB |
| 01_sample_02.txt | AC | 2 ms | 3384 KiB |
| 01_sample_03.txt | AC | 3 ms | 3580 KiB |
| 02_small_01.txt | AC | 4 ms | 3596 KiB |
| 02_small_02.txt | AC | 2 ms | 3424 KiB |
| 02_small_03.txt | AC | 2 ms | 3516 KiB |
| 02_small_04.txt | AC | 3 ms | 3436 KiB |
| 02_small_05.txt | AC | 1 ms | 3540 KiB |
| 02_small_06.txt | AC | 4 ms | 3520 KiB |
| 02_small_07.txt | AC | 2 ms | 3576 KiB |
| 02_small_08.txt | AC | 2 ms | 3496 KiB |
| 02_small_09.txt | AC | 2 ms | 3428 KiB |
| 02_small_10.txt | AC | 2 ms | 3572 KiB |
| 03_rand_01.txt | AC | 5 ms | 3840 KiB |
| 03_rand_02.txt | AC | 16 ms | 5700 KiB |
| 03_rand_03.txt | AC | 16 ms | 5724 KiB |
| 03_rand_04.txt | AC | 4 ms | 3580 KiB |
| 03_rand_05.txt | AC | 21 ms | 6320 KiB |
| 03_rand_06.txt | AC | 5 ms | 3868 KiB |
| 03_rand_07.txt | AC | 15 ms | 5584 KiB |
| 03_rand_08.txt | AC | 20 ms | 6768 KiB |
| 03_rand_09.txt | AC | 29 ms | 7240 KiB |
| 03_rand_10.txt | AC | 22 ms | 7368 KiB |
| 03_rand_11.txt | AC | 11 ms | 4156 KiB |
| 03_rand_12.txt | AC | 16 ms | 5012 KiB |
| 03_rand_13.txt | AC | 20 ms | 5512 KiB |
| 03_rand_14.txt | AC | 10 ms | 4488 KiB |
| 03_rand_15.txt | AC | 23 ms | 5700 KiB |
| 03_rand_16.txt | AC | 28 ms | 6628 KiB |
| 03_rand_17.txt | AC | 12 ms | 4392 KiB |
| 03_rand_18.txt | AC | 33 ms | 7508 KiB |
| 03_rand_19.txt | AC | 4 ms | 3704 KiB |
| 03_rand_20.txt | AC | 33 ms | 7824 KiB |
| 04_handmade_01.txt | AC | 29 ms | 8100 KiB |
| 04_handmade_02.txt | AC | 28 ms | 8192 KiB |
| 04_handmade_03.txt | AC | 17 ms | 8192 KiB |
| 04_handmade_04.txt | AC | 23 ms | 8104 KiB |
| 04_handmade_05.txt | AC | 23 ms | 8216 KiB |
| 04_handmade_06.txt | AC | 28 ms | 8060 KiB |
| 04_handmade_07.txt | AC | 32 ms | 8248 KiB |