Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define pb push_back
- #define F first
- #define S second
- #define ll long long
- using namespace std;
- int dp[512][123456];
- int main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- #ifdef LOCAL
- freopen("input.txt","r",stdin);
- freopen("output.txt","w",stdout);
- #endif
- int n,m;
- cin>>n>>m;
- vector <int> a(n);
- ll sum = 0;
- for ( int i = 0; i < n; i++ ) {
- cin>>a[i];
- sum += a[i];
- }
- if ( sum % m == 0 ) {
- cout<<n;
- return 0;
- }
- for ( int i = 0; i < n; i++ )
- dp[i][a[i]%m] = 1;
- for ( int i = 1; i < n; i++ ) {
- for ( int j = 0; j < m; j++ ) {
- if ( dp[i-1][j] != 0 ) dp[i][j] = max( dp[i][j], dp[i-1][j] + 0 );
- if ( dp[i-1][(j-a[i]+m)%m] != 0 ) dp[i][j] = max( dp[i][j], dp[i-1][(j-a[i]+m)%m] + 1 );
- }
- }
- for ( int i = 0; i < n; i++ ) {
- for ( int j = 0; j < m; j++ )
- cout<<dp[i][j]<<' ';
- cout<<endl;
- }
- cout<<dp[n-1][0];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement