Both CVS and Walgreens have their business model in "spend 30 minutes getting anything at the grocery store; spend 5 minutes getting it here [but pay more]."
I can run into HEB (the local grocery store chain in the better parts of Texas (suck it, Dallas)) and grab some Gatorade in about twenty minutes after parking way in the back of the huge parking lot, running across the huge store to the sports drink aisle, coming back to the register, waiting behind a bunch of people buying at minimum 15 items, and then cross the parking lot again to get to my car (while dodging tons of foot traffic and waiting in the driving lanes for minutes while some lazy bastard waits for some person who hasn't even started his car yet to back out so he can get the parking space about 20 feet closer to the entrance to the store.
Or I can go to Walgreens, pay $1 more for the drink, park right by the entrance, wait behind at most one or two people buying a mere couple items each, and walk out the door and there's my car. No one else is driving in the parking lot, so I'm in and out in five minutes.
Sometimes it's worth the extra $1 spent.
That is how Walgreens stays in business compared to the big grocery store. CVS is the same way down here.
K-Mart isn't in business anywhere around here, though. Maybe for the very reason you mentioned. The last K-Mart I saw closed about ten years ago in my hometown. I have not seen a K-Mart since then.