fork download
  1. // iostream is too mainstream
  2. #include <cstdio>
  3. // bitch please
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <cstdlib>
  7. #include <vector>
  8. #include <set>
  9. #include <map>
  10. #include <queue>
  11. #include <stack>
  12. #include <list>
  13. #include <cmath>
  14. #include <iomanip>
  15. #define dibs reserve
  16. #define OVER9000 1234567890
  17. #define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
  18. #define tisic 47
  19. #define soclose 1e-8
  20. #define chocolate win
  21. // so much chocolate
  22. #define patkan 9
  23. #define ff first
  24. #define ss second
  25. #define abs(x) ((x < 0)?-(x):x)
  26. #define uint unsigned int
  27. #define dbl long double
  28. using namespace std;
  29. // mylittledoge
  30.  
  31. int main() {
  32. cin.sync_with_stdio(0);
  33. cin.tie(0);
  34. int N,K,a;
  35. cin >> N >> K;
  36. multiset<int> S1,P;
  37. for(int i =0; i < N; i++) {
  38. cin >> a;
  39. S1.insert(a);} // 5*a
  40. for(int i =0; i < K; i++) {
  41. cin >> a;
  42. P.insert(a);} // 5*a
  43.  
  44. int ans =N;
  45. while(!S1.empty()) {
  46. if(P.empty()) {cout << "NIE\n"; return 0;}
  47. a =*S1.rbegin();
  48. S1.erase(--S1.end());
  49. if(*P.rbegin() >= 5*a) {
  50. P.erase(--P.end());
  51. continue;}
  52. ans++;
  53. auto it =P.lower_bound(3*a);
  54. if(it == P.end()) {cout << "NIE\n"; return 0;}
  55. P.erase(it);
  56. it =P.lower_bound(2*a);
  57. if(it == P.end()) {cout << "NIE\n"; return 0;}
  58. P.erase(it);}
  59.  
  60. cout << ans << "\n";
  61. return 0;}
  62.  
  63. // look at my code
  64. // my code is amazing
Time limit exceeded #stdin #stdout 5s 244864KB
stdin
Standard input is empty
stdout
Standard output is empty