Changing > to <= causes wrong answer when it practically doesn't matter!
source link: https://codeforces.com/blog/entry/110366
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Hi! I was solving 230A. Dragons when I encountered a strange problem.
I tried to solve it this way with the greedy method:
We make a pair< int, int > a[n]
array which puts the powers in the first component of the pairs and puts the bonuses in the second component (a[i].first = x[i], a[i].second = y[i]
). Then we sort the array a
by the first component (powers). The problem is in sorting the second component. We shouldn't care about second component (the bonus) while sorting right? Suppose all the powers are equal to p. If our current strength is lower than or equal to p, we can't proceed so we can't kill all the dragons. If it's greater that p, the we can kill all the dragons with the power of p regardless of getting any more bonus.
These are my submissions:
Submission 1
Submission 2
In one of them in the compare
function while comparing the second component of two pairs, I used > and in one of them I used <=. And in one of them I get wrong answer and in one of them the code gets accepted. Why is this happening? By the way, when I ran the "wrong" code in my computer with the same test cases, I got segmentation fault.
Thanks :)
Recommend
-
88
Cuckoo Filter Practically better than Bloom Filter. Cuckoo filters support adding and removing items dynamically while achieving even higher performance than Bloom filters. For applications that store many items and target moderately low...
-
195
Cross-Origin Resource Sharing (CORS) is a mechanism that uses additional HTTP headers to let a user agent gain permission to access selected resources from a server on a different origin (domain)…
-
8
Technically right but practically wrong for the classroom I've received some feedback on my multihead classroom computer post. I got a couple of messages which reminde...
-
15
印度STEM教育平台Practically宣布完成400万美元B轮融资_VR陀螺
-
6
𝐷𝑟. 𝐼𝑎𝑛 𝐶𝑢𝑡𝑟𝑒𝑠𝑠 on Twitter: "@gmourao To show iso-frewuency performance. It's very common, practically a de-facto standard if you follow this industry, to show new semi-con technology differences."Don’t miss what’s happeningPeopl...
-
6
’Ratchet and Clank: Rift Apart’ review: A practically flawless PlayStation 5 exclusiveThe best traits of modern Sony titles are manifest in “Ratchet and Clank: Rift Apart.” It is the greatest exclusive title for a PlayStation p...
-
6
POSTED ON JULY 9, 2021 TO Core Data, Data Infrastructure,
-
1
How to Practically Implement Microservices Infrastructure in Your Business ...
-
8
How to setup a practically free CDN I've been using Backblaze for a while now as my online backup service. I have used a few others in the past. None were particularly satisfactory until Backb...
-
6
What Causes Alzheimer’s? Scientists Are Rethinking the Answer.neurosc...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK