Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- */
- //#pragma comment(linker, "/STACK:16777216")
- #include <fstream>
- #include <iostream>
- #include <string>
- #include <complex>
- #include <math.h>
- #include <set>
- #include <vector>
- #include <map>
- #include <queue>
- #include <stdio.h>
- #include <stack>
- #include <algorithm>
- #include <list>
- #include <ctime>
- #include <memory.h>
- #include <ctime>
- #define y0 sdkfaslhagaklsldk
- #define y1 aasdfasdfasdf
- #define yn askfhwqriuperikldjk
- #define j1 assdgsdgasghsf
- #define tm sdfjahlfasfh
- #define lr asgasgash
- #define eps 1e-9
- //#define M_PI 3.141592653589793
- #define bs 1000000007
- #define bsize 256
- #define right adsgasgadsg
- #define free adsgasdg
- #define MAG 10000
- using namespace std;
- long long tests,n,m,s,q,val,ans;
- set<long long> S;
- set<long long>::iterator it;
- int main(){
- //freopen("hiking.in","r",stdin);
- //freopen("hiking.out","w",stdout);
- //freopen("C:/input.txt","r",stdin);
- //freopen("C:/output.txt","w",stdout);
- ios_base::sync_with_stdio(0);
- //cin.tie(0);
- cin>>tests;
- for (;tests;--tests)
- {
- cin>>n>>m;
- S.clear();
- s=0;
- S.insert(0);
- S.insert(m);
- ans=0;
- for (int i=1;i<=n;i++)
- {
- cin>>q;
- s+=q;
- s%=m;
- it=S.lower_bound(s);
- if ((*it)==s)++it;
- val=(*it);
- ans=max(ans,(m+s-val)%m);
- //cout<<s<<" "<<val<<endl;
- S.insert(s);
- S.insert(s+m);
- }
- cout<<ans<<endl;
- }
- cin.get();cin.get();
- return 0;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement