UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#203841#3569. 最优子序列GSRgsrgsr10092ms4720kbC++452b2024-03-24 10:10:442024-03-24 12:03:03

answer

#include<bits/stdc++.h>
#define ll long long 
using namespace std;
const int N=2e5+5;
int a[N];
ll f[N],g[N];
int main(){
//	freopen("a.in","r",stdin);
	int n,m;
	ll ans=0;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]);
		f[i]=a[i];
	}
	for(int i=1;i<=n;++i){
		f[i]=max(f[i],g[(m-a[i]%m)%m]+a[i]);
		g[a[i]%m]=max(g[a[i]%m],f[i]);
	}
	for(int i=1;i<=n;++i)ans=max(ans,f[i]);
	printf("%lld",ans);
	return 0;
} 

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1196kb

input:

20 13
749987623 375211210 944589514 64972338 389342463 507674971 991531334 890802757 32576979 781213...

output:

2166559486

result:

ok single line: '2166559486'

Test #2:

score: 10
Accepted
time: 0ms
memory: 1200kb

input:

20 15
99582796 12294885 852348789 926605817 849204941 270471458 892887566 974067892 841800457 157511...

output:

2612569905

result:

ok single line: '2612569905'

Test #3:

score: 10
Accepted
time: 0ms
memory: 1280kb

input:

20 114514
292793712 565481935 809761776 941466148 554645876 177476807 703263128 623014274 810635044 ...

output:

941466148

result:

ok single line: '941466148'

Test #4:

score: 10
Accepted
time: 0ms
memory: 1260kb

input:

5000 100
947291260 964017567 669765758 43013623 53333014 819988146 911217742 494187329 319940221 106...

output:

46295823400

result:

ok single line: '46295823400'

Test #5:

score: 10
Accepted
time: 1ms
memory: 1256kb

input:

5000 2
964428160 970707036 188825719 674826526 726016066 685695742 349231170 584008877 274267609 734...

output:

1268402153500

result:

ok single line: '1268402153500'

Test #6:

score: 10
Accepted
time: 0ms
memory: 1292kb

input:

5000 5000
972867911 291165229 665116301 137971950 441605559 496300169 443483413 438670482 148278584 ...

output:

4230095000

result:

ok single line: '4230095000'

Test #7:

score: 10
Accepted
time: 24ms
memory: 4720kb

input:

200000 151515
452179336 951343439 696121316 19484808 308437468 425400338 992090515 244609102 3305997...

output:

6555540551

result:

ok single line: '6555540551'

Test #8:

score: 10
Accepted
time: 26ms
memory: 3936kb

input:

200000 51113
667097295 591541403 926240086 85226095 181629757 152240070 721023193 735997444 65337067...

output:

9435153122

result:

ok single line: '9435153122'

Test #9:

score: 10
Accepted
time: 22ms
memory: 3540kb

input:

200000 177
166454880 278617410 567880671 333893483 19488273 411375222 356160463 802630092 539902174 ...

output:

737190980432

result:

ok single line: '737190980432'

Test #10:

score: 10
Accepted
time: 19ms
memory: 3540kb

input:

200000 14
585315962 94718848 884602638 130460488 727305959 336131767 678306907 786520584 588410644 6...

output:

8849689714432

result:

ok single line: '8849689714432'

Extra Test:

score: 0
Extra Test Passed