fork download
  1. /***********Template Starts Here***********/
  2. #include <bits/stdc++.h>
  3.  
  4. #define pb push_back
  5. #define nl puts ("")
  6. #define sp printf ( " " )
  7. #define phl printf ( "hello\n" )
  8. #define ff first
  9. #define ss second
  10. #define POPCOUNT __builtin_popcountll
  11. #define RIGHTMOST __builtin_ctzll
  12. #define LEFTMOST(x) (63-__builtin_clzll((x)))
  13. #define MP make_pair
  14. #define FOR(i,x,y) for(vlong i = (x) ; i <= (y) ; ++i)
  15. #define ROF(i,x,y) for(vlong i = (y) ; i >= (x) ; --i)
  16. #define CLR(x,y) memset(x,y,sizeof(x))
  17. #define UNIQUE(V) (V).erase(unique((V).begin(),(V).end()),(V).end())
  18. #define MIN(a,b) ((a)<(b)?(a):(b))
  19. #define MAX(a,b) ((a)>(b)?(a):(b))
  20. #define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
  21. #define SQ(x) ((x)*(x))
  22. #define ABS(x) ((x)<0?-(x):(x))
  23. #define FABS(x) ((x)+eps<0?-(x):(x))
  24. #define ALL(x) (x).begin(),(x).end()
  25. #define LCM(x,y) (((x)/gcd((x),(y)))*(y))
  26. #define SZ(x) ((vlong)(x).size())
  27. #define NORM(x) if(x>=mod)x-=mod;
  28.  
  29. using namespace std;
  30.  
  31. typedef long long vlong;
  32.  
  33. /***********Template Ends Here***********/
  34.  
  35. vlong arr[100010];
  36. vlong serve[10100];
  37.  
  38. struct node {
  39. int id;
  40. vlong cur;
  41.  
  42. node ( int a, vlong b ) {
  43. id = a;
  44. cur = b;
  45. }
  46. };
  47. class compare {
  48. public:
  49. bool operator () ( const node &a, node &b ) {
  50. if ( a.cur < b.cur ) return false;
  51. else if ( a.cur == b.cur && serve[a.id] < serve[b.id] ) return false;
  52. else return true;
  53. }
  54. };
  55.  
  56. int main () {
  57.  
  58. int kase;
  59. scanf ( "%d", &kase );
  60.  
  61. int cnt = 0;
  62.  
  63. while ( kase-- ) {
  64. int n, m;
  65. scanf ( "%d %d", &n, &m );
  66.  
  67. FOR(i,0,n-1) {
  68. scanf ( "%lld", &arr[i] );
  69. }
  70.  
  71. sort ( arr, arr + n, greater<vlong>() ); ///Sort in reverse order
  72.  
  73. priority_queue<node,vector<node>,compare> pq;
  74. FOR(i,0,m-1){
  75. scanf ( "%d", &serve[i] );
  76. pq.push ( node(i,0) );
  77. }
  78.  
  79. vlong res = 0;
  80. FOR(i,0,n-1){
  81. node temp = pq.top(); pq.pop();
  82.  
  83. vlong need = arr[i] + temp.cur;
  84. res = MAX(res,need);
  85.  
  86. pq.push ( node ( temp.id, temp.cur + serve[temp.id] ) );
  87. }
  88.  
  89. printf ( "Case %d: %lld\n", ++cnt, res );
  90. }
  91.  
  92. return 0;
  93. }
  94.  
Runtime error #stdin #stdout 0s 4276KB
stdin
Standard input is empty
stdout
Standard output is empty