
TLE了,不知为何
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int NN = 40;
int N, M, Ans;
int A[NN];
map<int, bool> Vis;
void Search(int num, int index){
if(index == N + 1)
return ;
// 选
if(Vis[(num + A[index]) % M] == false)
Vis[(num + A[index]) % M] = true,
Ans = max(Ans, (num + A[index]) % M),
Search((num + A[index]) % M, index + 1);
// 不选
Search(num, index + 1);
}
signed main(){
cin >> N >> M;
for(int i = 1; i <= N; i ++)
cin >> A[i];
// timespec begin;
// clock_gettime(CLOCK_MONOTONIC, &begin);
Search(0, 1);
printf("%lld", Ans);
// timespec end;
// clock_gettime(CLOCK_MONOTONIC, &end);
// printf("\n%.5lf", (double)(end.tv_nsec-begin.tv_nsec)/((double) 1e9) + (double)(end.tv_sec-begin.tv_sec));
return 0;
}