A seasonal artisan market cooperative asks every stall to self-report its net profit margin at the end of each year. Some stalls skip a year's report entirely, in which case that year is marked unreported rather than assumed to be zero. Before opening priority registration for next season's premium floor space, the market association wants the ids of every stall that was strictly profitable — reported a margin greater than zero — in one specific target year.
n y: the number of ledger entries, and the target year to check.n lines contains three space-separated tokens id year margin, where margin is either an integer or the literal token NA meaning that year was not reported for that stall.Print, one per line and in strictly ascending order, every distinct stall id that has an entry for year y with a reported margin strictly greater than 0. Ignore entries for any other year and ignore NA entries entirely. If no stall qualifies, print nothing.
year also satisfies 1 <= year <= 10000Example 1
Input
5 2024 101 2023 50 101 2024 30 102 2024 -10 103 2024 NA 104 2024 5
Expected
101 104
Explanation
Stall 101 has two ledger entries; only its 2024 entry (margin 30) matters for target year 2024, and 30>0, so 101 qualifies. Stall 102's 2024 margin is -10, not positive. Stall 103's 2024 entry is NA (unreported). Stall 104's 2024 margin is 5>0, so it qualifies. Sorted ascending, the answer is 101 then 104.
Example 2
Input
3 2025 201 2025 0 202 2025 NA 203 2024 100
Expected
(empty)Explanation
None of the three entries qualifies: stall 201's 2025 margin is exactly 0, not strictly positive; stall 202's 2025 entry is NA; and stall 203's only entry is for 2024, not the target year 2025. The output is therefore empty.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →