fork download
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5.  
  6. int main(void)
  7. {
  8. int T;
  9. cin>>T;
  10. while(T--)
  11. {
  12. int n, p;
  13. cin>>n>>p;
  14. int arr[n+1], i, j;
  15. for(i=0; i<n; i++)
  16. cin>>arr[i];
  17. arr[-1]=0;
  18. int max=0, sum=0, tot=0, count=0, temp;
  19. for(i=0; i<n; i++)
  20. {
  21. tot=tot+arr[i];
  22. sum=0;
  23. for(j=0; j<=i+1; j++)
  24. {
  25. sum=sum+arr[j-1];
  26. if((tot-sum)%p==max)
  27. count++;
  28. if((tot-sum)%p>max)
  29. {
  30. max=(tot-sum)%p;
  31. count=1;
  32. }
  33. }
  34. }
  35. cout<<max<<" "<<count<<"\n";
  36. }
  37.  
  38. return 0;
  39. }
  40.  
  41.  
  42.  
Success #stdin #stdout 0s 16064KB
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