fork download
  1. #include <iostream>
  2. using namespace std;
  3. int t,n,k,m,i,j;
  4. int lef[100002],righ[100002],cost[100002],a[100002],total=0;
  5. int swap(int *a, int *b)
  6. {
  7. int temp=*a;
  8. *a=*b;
  9. *b=temp;
  10. }
  11. int pivot(int l, int h)
  12. {
  13. int x=cost[h],i=l,j=l-1,temp;
  14. for(i=l;i<h;i++)
  15. {
  16. if(cost[i]<x)
  17. {
  18. j++;
  19. swap(&cost[i],&cost[j]);
  20. swap(&righ[i],&righ[j]);
  21. swap(&lef[i],&lef[j]);
  22. }
  23. }
  24. j++;
  25. swap(&cost[h],&cost[j]);
  26. swap(&lef[h],&lef[j]);
  27. swap(&righ[h],&righ[j]);
  28. return j;
  29. }
  30. int quick(int l, int h)
  31. {
  32. int p;
  33. if(l<h)
  34. {
  35. p=pivot(l,h);
  36. quick(l,p-1);
  37. quick(p+1,h);
  38. }
  39. }
  40. int main() {
  41. cin>>t;
  42. while(t--)
  43. {
  44. total=0;
  45. cin>>n>>k>>m;
  46. for(i=1;i<=n;i++)
  47. {
  48. cin>>a[i];
  49. total+=a[i];
  50. }
  51. for(i=1;i<=m;i++)
  52. cin>>lef[i]>>righ[i]>>cost[i];
  53. quick(1,m);
  54. for(i=1;i<=m;i++)
  55. cout<<lef[i]<<righ[i]<<cost[i]<<endl;
  56. }
  57. return 0;
  58. }
  59.  
Success #stdin #stdout 0s 4660KB
stdin
1
5 10 5
10 -2 -5 7 -10
1 1 5
2 4 10
4 4 12
3 4 10
1 5 15
stdout
115
3410
2410
4412
1515