Why is my greedy approach wrong for Codeforces 2248B?

I'm trying to solve Codeforces 2248B, and I came up with a multiset-based greedy approach.

My idea is the following:

For every b[i], I want to choose two elements from the current multiset:

  • lo = the smallest available a, preferably st.begin(), such that lo < b[i]
  • hi = the smallest available a greater than b[i]i.e.st.upper_bound(b[i])

Then I replace those two elements with b[i].

So conceptually:

auto lo = st.begin();
auto hi = st.upper_bound(b[i]);

if (lo == st.end() || *lo >= b[i] || hi == st.end()) {
    // impossible
}

st.erase(lo);
st.erase(hi);
st.insert(b[i]);

I initially implemented something very similar:

sort(a.begin(), a.end());
sort(b.begin(), b.end());

multiset<ll> st(a.begin(), a.end());

if (n < 2 * m) {
    cout << "NO\n";
    return;
}

for (int i = 0; i < m; i++) {
    auto hi_it = st.lower_bound(b[i]);
    if (hi_it == st.begin() || hi_it == st.end()) {
        cout << "NO\n";
        return;
    }

    auto lo_it = st.begin();

    st.erase(lo_it);
    st.erase(hi_it);
    st.insert(b[i]);
}

cout << "YES\n";

My intuition is that choosing the smallest possible lower element should be safe because it leaves all the larger elements available for future b[i] values.

Similarly, choosing the smallest possible upper element should also be safe because I'm consuming the closest possible value above b[i] rather than wasting a larger value.

My intuition is that choosing the smallest possible lower element should be safe because it leaves all the larger elements available for future b[i] values.Similarly, choosing the smallest possible upper element should also be safe because I'm consuming the closest possible value above b[i] rather than wasting a larger value.

However, I understand that my greedy choice is apparently not correct.
What I'm struggling with is understanding exactly where the logic breaks.

reddit.com
u/Ill-Question-2316 — 2 days ago
▲ 3 r/resumesindia+1 crossposts

Resume Review – Looking for Backend/SDE/Full-Stack Roles (2026 Grad)

I'm a final-year BE (IT) student graduating in a few months and currently looking for Backend, SDE, and Full-Stack roles.

I'd really appreciate any feedback on my resume—whether it's the content, formatting, project descriptions, or anything else that could improve my chances of getting interviews.

Any suggestions are welcome. Thanks!

https://preview.redd.it/1m9k16j3shhh1.png?width=650&format=png&auto=webp&s=323fdb2b9af9a3b584c1f7e3c17fdd23e1fbe50b

reddit.com
u/Ill-Question-2316 — 17 days ago

How much is my Gigabyte RTX 3060 12GB OC worth with an intermittent hardware issue?

I have a Gigabyte RTX 3060 12GB Gaming OC (out of warranty) and I'm trying to figure out a fair selling price.

Condition:

  • Boots and gives display normally.
  • Drivers install fine.
  • Games usually run fine.
  • Passes stress tests most of the time, but randomly crashes around 1 out of every 5 stress test runs (or occasionally under heavy load).
  • Based on previous troubleshooting, I suspect it could be a VRM/power delivery issue, but it has not been professionally diagnosed, so I'm selling it as faulty/as-is.
  • I contacted the official Gigabyte service center, but since the card is out of warranty, they do not offer board-level repairs.

For context, around the same time my motherboard also failed, so I initially suspected a power-related issue, but I can't confirm whether the GPU problem is related.

What would be a fair asking price in India for a card in this condition? I'm looking for realistic estimates from people who've bought or sold repairable GPUs.

reddit.com
u/Ill-Question-2316 — 2 months ago

Need review on this tech-guru-store website

I just want to know reviews for this website I found selling rams at a very low price and wanted to confirm.

Also I want to buy a used 32gb ram 5600mhz ddr5 ram for my new pc build.

Website : techgurustore (dot) in

u/Ill-Question-2316 — 2 months ago

Selling Corsair vengeance ddr4 ram

Selling Corsair vengeance 8*2 16gb 3200mhz ram around 5k negotiable (location - Mumbai ) , f2f preferred

u/Ill-Question-2316 — 2 months ago

Is this build worth it ?

After visiting each shop at lamington road, these are the prices which I found to be the lowest .

Is this good pc build around 110-125k ?

And also confused between 9060xt and 5060ti and 9600x/7700x .

[edit-1] My PC Build -1 (9600x-9060xt) Reusing Cabinet,cooler (SSD:-can go for NVME/SSD of crucial/etc) <- cut cost (PSU:-same but offline better price) <- cut cost

CPU: AMD Ryzen 5 9600X 3.9 GHz 6-core Processor - ₹20,690.00 @ Computech Store Motherboard: Gigabyte B650M D3HP AX Micro ATX AM5 - ₹10,899.00 @ Computech Store Graphics Card 1: Gigabyte Radeon RX 9060 XT GAMING OC 16G 16 GB GDDR6 - ₹45,499.00 @ Computech Store RAM 1: Kingston Fury Beast 16GB DDR5 (1 x 16GB) 5600MHz 36 (KF556C36BBE-16) - ₹18,399.00 @ Computech Store Storage 1: WD Green SN350 500GB SSD M.2 PCIe 3.0 x 4 (WDS500G2G0C) - ₹7,397.00 @ Elitehubs Power Supply: Corsair CX Series CX650 ATX 650 W 80 PLUS Bronze - ₹4,794.00 @ Computech Store UPS: APC Back-UPS 1100VA BX1100C-IN - ₹6,985.00 @ Easy Shoppi Total: ₹1,14,663 Build Link: https://pickpcparts.in/build-pc/build/cmw22UX

u/Ill-Question-2316 — 2 months ago

I’ve been troubleshooting a really strange issue over the past few days and I’ve narrowed it down quite a bit, but I’d like some confirmation before taking the next step.

  • Random black screen followed by restart (restart temporarily fixes it)

  • Happens consistently under load (games like RDR2, LLM workloads, etc.)

  • Sometimes a complete instant shutdown (no BSOD, no error.

  • Temps → completely normal (monitored via HWiNFO, no overheating of any component)

  • Event Viewer → only Kernel-Power 41 after crash

  • No driver crashes, no WHEA errors

System specs

  • CPU: Ryzen 5 5600X
  • RAM: 16GB (8×2) 3200 MHz
  • Motherboard: Gigabyte B450M DS3H
  • PSU: Cooler Master 550W Bronze
  • Storage: SSDs + HDD
  • (All components bought around end of 2022, out of warranty)

Earlier my NVIDIA GeForce RTX 3060 had overheating issues, so I got it repaired from a service center. After that, the overheating was fixed, but I kept getting black screen issues for a long time.

Isolation testing (done by local repair shop)

They tested by swapping components, and the result was very clear:

  • With my NVIDIA GeForce RTX 3060 → crashes/shutdown still happen
  • With a NVIDIA GeForce RTX 3070 (same system, same PSU, same cables) → completely stable

At this point:

  • Is my 3060 basically failing (likely power delivery/VRM issue)?
  • Or is there anything else worth checking before replacing it?

Should I:

  • Replace just the GPU
  • Or consider upgrading the whole system?
reddit.com
u/Ill-Question-2316 — 4 months ago