fork(1) download
  1. /*
  2.  * File: lelemon.cpp
  3.  * Author: Ayush
  4.  *
  5.  * Created on December 21, 2014, 10:36 PM
  6.  */
  7.  
  8. #include<iostream>
  9.  
  10. using namespace std;
  11.  
  12. long long arr[102][102], room[10001];
  13.  
  14. int main(int argc, char** argv)
  15. {
  16. long long n, m, t;
  17. cin>>t;
  18. while (t--)
  19. {
  20. long long ans = 0, row=0, c=0,max=0,col=0,i,j,visit[10000]={0};
  21. cin >> n>>m;
  22. for (i = 0; i < m; i++)
  23. cin >> room[i];
  24. for (i = 0; i < n; i++)
  25. {
  26. cin >>arr[i][101];
  27. for (j = 0; j < arr[i][101]; j++)
  28. cin >> arr[i][j];
  29. }
  30. for (i = 0; i < m; i++)
  31. {
  32. row = room[i];
  33. c = arr[row][101];
  34. if(visit[i]==c)
  35. continue;
  36. visit[i]++;
  37. max=arr[row][0];
  38. for(j=1;j<c;j++)
  39. {
  40. if(arr[row][j]>=max)
  41. {
  42. max=arr[row][j];
  43. col=j;
  44. }
  45. }
  46. arr[row][col]=0;
  47. ans += max;
  48. }
  49. cout << ans << "\n";
  50. }
  51. return 0;
  52. }
  53.  
  54.  
Success #stdin #stdout 0s 3504KB
stdin
2
3 3
0 2 1
3 1 2 3
1 7
2 4 7
4 7
0 1 3 0 1 0 0
1 7
3 9 4 5
7 1 2 3 4 5 6 7
1 1
stdout
17
22