fork download
  1. #include <bits/stdc++.h>
  2. #define endl '\n'
  3.  
  4. #define int unsigned
  5.  
  6. using namespace std;
  7. const int MAXN = (1 << 20);
  8.  
  9. void Read(int &x);
  10.  
  11. int n;
  12. int c[3];
  13. int a[MAXN];
  14. set<pair<int, int> > s;
  15.  
  16. void read()
  17. {
  18. Read(n);
  19.  
  20. for(int i = 0; i < 3; i++)
  21. Read(c[i]);
  22.  
  23. int ssda = 1;
  24. for(int i = 0; i < n; i++)
  25. {
  26. int val;
  27. Read(val);
  28. s.insert({val, ssda++});
  29. }
  30. }
  31.  
  32. void stop()
  33. {
  34. printf("-1\n");
  35. fflush(stdin);
  36. exit(0);
  37. }
  38.  
  39. void solve()
  40. {
  41. sort(c, c + 3);
  42.  
  43. set<pair<int, int> >::iterator it, x, y, f;
  44. int ans = 0, last_sz = -1;
  45. while(s.size() != 0)
  46. {
  47. if(last_size == s.size())
  48. {
  49. ans = -1;
  50. break;
  51. }
  52. last_sz = s.size();
  53. it = --s.end();
  54.  
  55. int val = it->first;
  56. if(c[0] + c[1] + c[2] < val)
  57. {
  58. ans = -1;
  59. break;
  60. }
  61. if(c[1] + c[2] < val)
  62. {
  63. ans++;
  64. s.erase(it);
  65. continue;
  66. }
  67.  
  68. if(c[0] >= val)
  69. {
  70. s.erase(it);
  71. ans++;
  72. y = s.lower_bound({c[2], 0}), f = s.lower_bound({c[1] + c[2], 0});
  73.  
  74. if((f == s.end() || f->first > c[1] + c[2]) && f != s.begin()) --f;
  75. if((y == s.end() || y->first > c[2]) && y != s.begin()) --y;
  76.  
  77. if(y == s.end() || y->first > c[2])
  78. {
  79. if(f == s.end()) continue;
  80. if(f->first <= c[1] + c[2]) s.erase(f);
  81. else if(f != s.begin()) s.erase(--f);
  82.  
  83. continue;
  84. }
  85.  
  86. if(y->first <= c[2]) s.erase(y);
  87. else if(y != s.begin()) s.erase(--y);
  88.  
  89. x = s.lower_bound({c[1], 0});
  90. if((x == s.end() || x->first > c[1]) && x != s.begin()) --x;
  91.  
  92. if(x->first <= c[1]) s.erase(x);
  93. else if(x != s.begin()) s.erase(--x);
  94.  
  95. continue;
  96. }
  97.  
  98.  
  99. if(c[1] >= val)
  100. {
  101. s.erase(it);
  102. ans++;
  103.  
  104. y = s.lower_bound({c[2], 0}), f = s.lower_bound({c[2] + c[0], 0});
  105.  
  106. if((f == s.end() || f->first > c[2] + c[0]) && f != s.begin()) --f;
  107. if((y == s.end() || y->first > c[2]) && y != s.begin()) --y;
  108.  
  109. if(y == s.end() || y->first > c[2])
  110. {
  111. if(f == s.end()) continue;
  112. if(f->first <= c[2] + c[0]) s.erase(f);
  113. else if(f != s.begin()) s.erase(--f);
  114.  
  115. continue;
  116. }
  117.  
  118. if(y->first <= c[2]) s.erase(y);
  119. else if(y != s.begin()) s.erase(--y);
  120.  
  121. x = s.lower_bound({c[0], 0});
  122. if((x == s.end() || x->first > c[0]) && x != s.begin()) --x;
  123.  
  124. if(x->first <= c[0]) s.erase(x);
  125. else if(x != s.begin()) s.erase(--x);
  126.  
  127. continue;
  128. }
  129. if(c[2] >= val)
  130. {
  131. s.erase(it);
  132. ans++;
  133. y = s.lower_bound({c[1], 0}), f = s.lower_bound({c[1] + c[0], 0});
  134.  
  135. if((f == s.end() || f->first > c[1] + c[0]) && f != s.begin()) --f;
  136. if((y == s.end() || y->first > c[1]) && y != s.begin()) --y;
  137.  
  138. if(y == s.end() || y->first > c[1])
  139. {
  140. if(f == s.end()) continue;
  141. if(f->first <= c[1] + c[0]) s.erase(f);
  142. else if(f != s.begin()) s.erase(--f);
  143.  
  144. continue;
  145. }
  146.  
  147.  
  148. if(y->first <= c[1]) s.erase(y);
  149. else if(y != s.begin()) s.erase(--y);
  150.  
  151. x = s.lower_bound({c[0], 0});
  152. if((x == s.end() || x->first > c[0]) && x != s.begin()) --x;
  153.  
  154. if(x->first <= c[0]) s.erase(x);
  155. else if(x != s.begin()) s.erase(--x);
  156.  
  157. continue;
  158. }
  159.  
  160. if(c[0] + c[1] >= val)
  161. {
  162. s.erase(it);
  163. ans++;
  164.  
  165. f = s.lower_bound({c[2], 0});
  166.  
  167. if(f == s.end() && f == s.begin()) continue;
  168. if(f == s.end()) --f;
  169.  
  170. if(f->first <= c[2]) s.erase(f);
  171. else if(f != s.begin()) s.erase(--f);
  172.  
  173. continue;
  174. }
  175.  
  176. if(c[0] + c[2] >= val)
  177. {
  178. s.erase(it);
  179. ans++;
  180.  
  181. f = s.lower_bound({c[1], 0});
  182.  
  183. if(f == s.end() && f == s.begin()) continue;
  184. if(f == s.end()) --f;
  185.  
  186. if(f->first <= c[1]) s.erase(f);
  187. else if(f != s.begin()) s.erase(--f);
  188.  
  189. continue;
  190. }
  191.  
  192. if(c[1] + c[2] >= val)
  193. {
  194. s.erase(it);
  195. ans++;
  196.  
  197. f = s.lower_bound({c[0], 0});
  198.  
  199. if(f == s.end() && f == s.begin()) continue;
  200. if(f == s.end()) --f;
  201.  
  202. if(f->first <= c[0]) s.erase(f);
  203. else if(f != s.begin()) s.erase(--f);
  204.  
  205. continue;
  206. }
  207. }
  208.  
  209. printf("%d\n", ans);
  210. fflush(stdin);
  211. }
  212.  
  213. #undef int
  214. int main()
  215. {
  216. //freopen("in.in", "r", stdin);
  217.  
  218. read();
  219. solve();
  220. return 0;
  221. }
  222.  
  223. #define int unsigned
  224.  
  225. #define maxl 100000
  226. char sir[maxl];
  227. int pos = 0;
  228.  
  229. void Next()
  230. {
  231. if (++pos == maxl) fread (sir, 1, maxl, stdin), pos = 0;
  232. }
  233.  
  234. void Read(int &x)
  235. {
  236. for (;sir[pos] < '0' || sir[pos] > '9'; Next ());
  237. for (x = 0; sir[pos] >= '0' && sir[pos] <= '9'; Next ()) x = x * 10 + sir[pos] - '0';
  238. }
  239.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'void solve()':
prog.cpp:47:6: error: 'last_size' was not declared in this scope
   if(last_size == s.size())
      ^
stdout
Standard output is empty