QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#73408#3032. Cheese Gamezhangboju#AC ✓57ms4704kbC++14604b2023-01-25 09:30:042023-01-25 09:30:06

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-25 09:30:06]
  • 评测
  • 测评结果:AC
  • 用时:57ms
  • 内存:4704kb
  • [2023-01-25 09:30:04]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
template <typename T> inline void read(T &x)
{
	x=0;short f=1;char c=getchar();
	for(;c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
	for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
	x*=f;return;
}
const int N=1e5+5;
#define ll long long
int n,a[N];
ll f[N];
int main()
{
	int T;read(T);
	while(T--)
	{
		read(n);
		for(int i=1;i<=n;++i) read(a[i]);
		memset(f,0,sizeof f);
		f[1]=a[1],f[2]=a[2];
		for(int i=3;i<=n;++i)
			f[i]=max(f[i-2]+a[i],f[i-3]+a[i]+min(a[i-1],a[i-2]));
		printf("%lld\n",*max_element(f+1,f+n+1));
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 4316kb

input:

20
2
2 1
1
1000000
4
3 2 4 3
8
1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000
8
1000000 1000000 1000000 1 1000000 1000000 1000000 1000000
9
723059 133070 898168 961394 18457 175012 478043 176230 377374
8
289384 930887 692778 636916 747794 238336 885387 760493
8
516650 641422 202363 ...

output:

2
1000000
8
5000000
5000000
2691397
3314426
2475496
4999998
10
3
1
2
8
4000001
15
3213803
24
3000002
4

result:

ok 20 lines

Test #2:

score: 0
Accepted
time: 57ms
memory: 4704kb

input:

20
100000
859485 390674 819590 695284 505824 962572 577989 53378 307332 754253 103728 302519 19948 48169 659522 389802 262161 848413 224854 965949 70782 789156 772974 876205 410327 900390 392837 362222 582187 762071 74734 958024 152744 410676 169659 174919 373247 264000 744649 196931 18252 848376 15...

output:

33024883937
33135467117
66667000000
33237375393
58332975002
33104918259
33172888838
33156623430
33090460100
33042109608
32999667097
33111199056
3333366667
32982135568
33144273501
56831006063
33108905993
33124668910
33126313979
33069028435

result:

ok 20 lines