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