NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

For everyone struggling with deleg's greedy :):

The correct if statements (logically speaking) at the end of the dfs should be:

if(loLessThanK>1) ok = false;
else if(loLessThanK==1 && cur == 1) ok = false;

if(leftover.size() == 0) dp[cur] = 0; //No leftovers
else dp[cur] = *leftover.rbegin(); //leftovers greater than k.

Most of that is self-explanatory, besides the combination of the 2nd and 4th statements. Originally, we discussed putting dp[cur] = *leftover.begin() in the second statement, so that might look odd.
They work because if loLessThanK is 1, one of the elements < K were unable to be matched with any other element. As a result, it is the only element in leftover. That can be easily be proven: if that element >= k, it should have been matched with the one in leftover right now. If not and that element < k, loLessThanK wouldn't be 1, and ok would have already been declared false in the first if statement. That's why taking the last value in leftover works even when loLessThanK is 1.
Additionally, we are always looking for the best value to take along with us to the parent. As a result, taking the last value in leftover makes sense for all other cases.
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.