1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| #include<bits/stdc++.h> using namespace std; int n,m,v[5001],mod[5001],dp[5001][5001]; int main() { freopen("abyss.in","r",stdin); freopen("abyss.out","w",stdout); memset(dp,-0x3f3f3f,sizeof(dp)); scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { scanf("%d",&v[i]); mod[i]=v[i]%m; } dp[0][0]=0; for(int i=1;i<=n;i++) for(int j=0;j<m;j++) { dp[i][j]=max(dp[i-1][j],dp[i][j]); dp[i][j]=max(dp[i][j],dp[i-1][(j-mod[i]+m)%m]+v[i]); } printf("%d",dp[n][0]); return 0; }
|