fork download
  1. #include <bits/stdc++.h>
  2.  
  3. #define pb push_back
  4. #define nl puts ("")
  5. #define sp printf ( " " )
  6. #define phl printf ( "hello\n" )
  7. #define ff first
  8. #define ss second
  9. #define POPCOUNT __builtin_popcountll
  10. #define RIGHTMOST __builtin_ctzll
  11. #define LEFTMOST(x) (63-__builtin_clzll((x)))
  12. #define MP make_pair
  13. #define FOR(i,x,y) for(vlong i = (x) ; i <= (y) ; ++i)
  14. #define ROF(i,x,y) for(vlong i = (y) ; i >= (x) ; --i)
  15. #define CLR(x,y) memset(x,y,sizeof(x))
  16. #define UNIQUE(V) (V).erase(unique((V).begin(),(V).end()),(V).end())
  17. #define MIN(a,b) ((a)<(b)?(a):(b))
  18. #define MAX(a,b) ((a)>(b)?(a):(b))
  19. #define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
  20. #define SQ(x) ((x)*(x))
  21. #define ABS(x) ((x)<0?-(x):(x))
  22. #define FABS(x) ((x)+eps<0?-(x):(x))
  23. #define ALL(x) (x).begin(),(x).end()
  24. #define LCM(x,y) (((x)/gcd((x),(y)))*(y))
  25. #define SZ(x) ((vlong)(x).size())
  26. #define NORM(x) if(x>=mod)x-=mod;
  27.  
  28. using namespace std;
  29.  
  30. typedef long long vlong;
  31.  
  32. int arr[1000010];
  33.  
  34. int main () {
  35.  
  36. int kase;
  37. scanf ( "%d", &kase );
  38.  
  39. int cnt = 0;
  40. while ( kase-- ) {
  41. int n, k;
  42. scanf ( "%d %d", &n, &k );
  43.  
  44. FOR(i,0,n-1) {
  45. scanf ( "%d", &arr[i] );
  46. arr[i] *= -1;
  47. }
  48.  
  49. FOR(i,0,n-1) {
  50. int t;
  51. scanf ( "%d", &t );
  52. arr[i] += t;
  53. }
  54.  
  55. ///arr[i] contains ( what that shop gives shamsu - what shamsu gives to godfather)
  56.  
  57. vlong res = 0;
  58. sort ( arr, arr + n ); ///Now, losses come first and profit comes later.
  59.  
  60. FOR(i,0,n-1) {
  61. if ( arr[i] < 0 ) { ///This is a loss
  62. if ( k ) { ///I can still skip loss
  63. k--;
  64. continue;
  65. }
  66. }
  67. res += arr[i];
  68. }
  69.  
  70. printf ( "Case %d: ", ++cnt );
  71. if ( res <= 0 ) printf ( "No Profit\n" );
  72. else printf ( "%lld\n", res );
  73. }
  74.  
  75. return 0;
  76. }
  77.  
Runtime error #stdin #stdout 0s 7360KB
stdin
Standard input is empty
stdout
Standard output is empty