#include<bits/stdc++.h> using namespace std; int main() { int n,a; cin>>n>>a; vector<int> nums(n); for(int i=0;i<n;i++) { cin>>nums[i]; } vector<int> feature(n); int current_max=nums[0]; int global_max=nums[0]; feature[0]=nums[0]; for(int i = 1; i < n; i++) { current_max=max(nums[i], current_max + nums[i]); global_max=max(global_max, current_max); feature[i]=global_max; } vector<int> score(n); score[0]=feature[0]; int max_score_plus_feature = score[0] + feature[0]; for(int i=1;i<n; i++) { score[i]=max_score_plus_feature; max_score_plus_feature = max(max_score_plus_feature, score[i] + feature[i]); } int max_score=*max_element(score.begin(),score.end()); if(max_score>=0){ cout<<max_score%a<<endl; }else{ cout<<"-"<<(-max_score)%a<<endl; } return 0; } /************************************************************** Problem: 1800 User: linxichen Language: C++ Result: Wrong Answer ****************************************************************/