I've spent time in both Kyiv and Lviv. Depending on your tastes and how in depth you want to see both places, you may want around 2 - 3 days in each location. It is possible to see all of the highlights in each city in the course of a long day, but you will feel rushed to do so. You should also consider Odessa if the train schedule is cooperative. My experience was pretty much in-line with the guide books (I don't have any secrets or considerations that aren't already covered by Lonely Planet et al.) However, I will say not to miss the Lychakiv cemetery while in Lviv. It turned out to be one of my favorite places in Lviv and some will skip it because you have to leave the main part of town to get there.
While you are on a tight budget, you should also look into the possibility of taking a domestic flight back to Kyiv. Depending on your route and how far you go into Western/Southwestern Ukraine, getting back to Kyiv with a flight will save you a lot of time.
Also, the trains can be a bit of an adventure. I highly recommend getting a sleeper cabin if you're on a night train. Some trains have two-bed sleepers, but on others the best available is a four-bed sleeper. You could be sharing space with just about anyone (This is usually fine and safe.) If you have a set itinerary before you leave, you can buy tickets ahead of time on the Ukrainian Railways website. It also allows you to select your exact cabin and seats/beds.
The biggest obstacle you will have is the language barrier. If you have a background in Russian or other language that uses the Cyrillic alphabet, you should be able to get by. English is not widely spoken, although the younger generation is now learning it. We had a number of adventures trying to communicate. We survived, but some "conversations" took much longer than they should have!