SUBANGKAR

CF-0888E

Nov 9th, 2017
91
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #define _SCL_SECURE_NO_WARNINGS
  3.  
  4. #include <iostream>
  5. #include <iomanip>
  6. #include <algorithm>
  7. #include <string>
  8. #include <vector>
  9. #include <list>
  10. #include <stack>
  11. #include <queue>
  12. #include <cstring>
  13. #include <cstdio>
  14. #include <map>
  15. #include <set>
  16. #include <bitset>
  17. #include <cmath>
  18.  
  19. typedef long long ll;
  20.  
  21.  
  22.  
  23.  
  24. using namespace std;
  25.  
  26.  
  27. #define pb push_back
  28. #define pp pop
  29. #define ins insert
  30. #define rmv remove
  31. //#include<bits/stdc++>
  32.  
  33.  
  34.  
  35. int main()
  36. {
  37.     int n, m;
  38.     cin >> n >> m;
  39.  
  40.     vector<int> a;
  41.     ll opt[n + 1];
  42.  
  43.  
  44.     a.push_back(0);
  45.  
  46.     for (int i = 0; i < n; i++)
  47.     {
  48.         ll x;
  49.         cin >> x;
  50.         a.pb(x%m);
  51.     }
  52.  
  53.     opt[0] = 0;
  54.     for (int i = 1; i <= n; i++)
  55.     {
  56.         opt[i] = max((opt[i - 1] + a[i]) % m, opt[i - 1]);
  57.     }
  58.  
  59.     cout << opt[n] << endl;
  60.  
  61.     return 0;
  62. }
RAW Paste Data