fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define endl "\n"
  4. int main() {
  5. int s=0,n,x,i,m,ctr,t,p=0;
  6. cin>>t;
  7. while(t--){
  8. cin>>n>>p;
  9. ctr=1;
  10. int a[n];
  11. cin>>m;
  12. a[0]=m;
  13. s=m;
  14. m=m%p;
  15. for(x=1;x<n;x++){
  16. cin>>a[x];
  17. i=a[x]%p;
  18. if(i>m){
  19. ctr=1;
  20. m=i;
  21. }
  22. else if(i==m) ctr++;
  23. s+=a[x]%p;
  24. i=s%p;
  25. if(i>m){
  26. ctr=1;
  27. m=i;
  28. }
  29. else if(i==m) ctr++;
  30.  
  31. }
  32. for(x=1;x<n-1;x++){
  33. s=a[x];
  34. for(int y=x+1;y<n;y++){
  35. s+=a[y]%p;
  36. i=s%p;
  37. if(i>m){
  38. ctr=1;
  39. m=i;
  40. }
  41. else if(i==m) ctr++;
  42. }
  43. }
  44. cout<<m<<" "<<ctr<<endl;
  45. }
  46. return 0;
  47. }
  48.  
Success #stdin #stdout 0s 16048KB
stdin
4
2 3
1 2
3 5
2 4 3
3 100
1 3 5
4 3
1 2 3 4
stdout
2 1
4 2
9 1
2 2