UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#203864#3569. 最优子序列jane100114ms5876kbC++11547b2024-03-24 11:17:462024-03-24 12:05:29

answer

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n;
long long a[N],m,ans;
long long mod,f[N],la[N];
int main(){
    scanf("%d%lld",&n,&m);
    for(int i=1;i<=n;i++)
        scanf("%lld",&a[i]);
    f[0]=0;
    memset(la,0,sizeof(la));
    for(int i=1;i<=n;i++){
    	mod=a[i]%m;
        if(mod==0)
            f[i]=f[la[0]]+a[i];
        else
            f[i]=f[la[m-mod]]+a[i];
        if(f[la[mod]]<=f[i])
        	la[mod]=i;
        ans=max(ans,f[i]);
    }
    printf("%lld\n",ans);
    return 0;
}

详细

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

Test #1:

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

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: 2756kb

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: 2760kb

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: 2840kb

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: 2ms
memory: 2840kb

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: 2ms
memory: 2840kb

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: 30ms
memory: 5872kb

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: 29ms
memory: 5876kb

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: 23ms
memory: 5876kb

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: 28ms
memory: 5876kb

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