Advertisement
Guest User

Untitled

a guest
Apr 10th, 2015
1,480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. /*
  2. */
  3.  
  4. //#pragma comment(linker, "/STACK:16777216")
  5. #include <fstream>
  6. #include <iostream>
  7. #include <string>
  8. #include <complex>
  9. #include <math.h>
  10. #include <set>
  11. #include <vector>
  12. #include <map>
  13. #include <queue>
  14. #include <stdio.h>
  15. #include <stack>
  16. #include <algorithm>
  17. #include <list>
  18. #include <ctime>
  19. #include <memory.h>
  20. #include <ctime>
  21.  
  22. #define y0 sdkfaslhagaklsldk
  23. #define y1 aasdfasdfasdf
  24. #define yn askfhwqriuperikldjk
  25. #define j1 assdgsdgasghsf
  26. #define tm sdfjahlfasfh
  27. #define lr asgasgash
  28.  
  29. #define eps 1e-9
  30. //#define M_PI 3.141592653589793
  31. #define bs 1000000007
  32. #define bsize 256
  33. #define right adsgasgadsg
  34. #define free adsgasdg
  35. #define MAG 10000
  36.  
  37. using namespace std;
  38.  
  39. long long tests,n,m,s,q,val,ans;
  40. set<long long> S;
  41. set<long long>::iterator it;
  42.  
  43. int main(){
  44. //freopen("hiking.in","r",stdin);
  45. //freopen("hiking.out","w",stdout);
  46. //freopen("C:/input.txt","r",stdin);
  47. //freopen("C:/output.txt","w",stdout);
  48. ios_base::sync_with_stdio(0);
  49. //cin.tie(0);
  50.  
  51. cin>>tests;
  52. for (;tests;--tests)
  53. {
  54. cin>>n>>m;
  55. S.clear();
  56. s=0;
  57. S.insert(0);
  58. S.insert(m);
  59. ans=0;
  60. for (int i=1;i<=n;i++)
  61. {
  62. cin>>q;
  63. s+=q;
  64. s%=m;
  65. it=S.lower_bound(s);
  66. if ((*it)==s)++it;
  67.  
  68. val=(*it);
  69. ans=max(ans,(m+s-val)%m);
  70. //cout<<s<<" "<<val<<endl;
  71. S.insert(s);
  72. S.insert(s+m);
  73. }
  74. cout<<ans<<endl;
  75. }
  76.  
  77. cin.get();cin.get();
  78. return 0;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement