inlinevoidyhm_clear() { sum = 0; while (! q.empty()) q.pop(); while (! yh.empty()) yh.pop(); return; }
inlinevoidyhm_func() { int i, j; n = read(), m = read(); for (i = 1; i <= n; ++ i) a[i] = read(); for (i = 1; i <= n; ++ i) { while (! yh.empty() && ! q.empty() && q.top() > yh.top()) { yh.push(q.top()); sum -= q.top(); q.pop(); } while (! yh.empty() && sum + yh.top() <= m - a[i]) { sum += yh.top(); q.push(yh.top()); yh.pop(); } if (sum <= m - a[i]) { q.push(a[i]), sum += a[i]; while (! yh.empty() && sum + yh.top() <= m) { sum += yh.top(); q.push(yh.top()); yh.pop(); } } else { while (! q.empty() && sum > m - a[i]) { sum -= q.top(); yh.push(q.top()); q.pop(); } q.push(a[i]); sum += a[i]; } put(yh.size()); } return (void)(puts("")); }