NWERC 2017 Open Contest


2017-11-26 11:30 CET

NWERC 2017 Open Contest


2017-11-26 16:30 CET
The end is near!
Contest is over.
Not yet started.
Contest is starting in -235 days 2:41:22

Time elapsed


Time remaining


Problem I
Installing Apps

Mobile radio telephone, public domain
Sandra recently bought her first smart phone. One of her friends suggested a long list of applications (more commonly known as “apps”) that she should install on the phone. Sandra immediately started installing the apps from the list, but after installing a few, the phone did not have enough disk space to install any more apps. Sometimes, the app installation failed because there was not even enough space to download the installation package. Other apps could be downloaded just fine, but had insufficient space to store the installed app.

Each app that Sandra installs has a download size $d$ and a storage size $s$. To download the app, Sandra’s phone must have at least $d$ megabytes of free disk space. After the app has been installed, it then uses $s$ megabytes of disk space on the phone. The download size may be smaller than the storage size (e.g., if the app data is heavily compressed) or larger than the storage size (e.g., if the download contains material that might not get used such as translations to different languages). The installer is very efficient and can transform the downloaded package to an installed app without using any extra disk space. Thus, to install an app, the phone must have at least $\max (d, s)$ megabytes of free disk space.

Sandra quickly realised that she may have run out of space just because she installed apps in the wrong order. Thus, she decided to give the installation another try. She uninstalled all apps, and will now choose an installation order that lets her install the largest number of apps from the list. Sandra may not install any app more than once.

Help her determine what apps on the list she should install, and in what order.


The input consists of:

  • One line with two integers $n$, $c$ ($1 \le n \le 500, 1 \le c \le 10\, 000$), the number of available apps and the available disk space of the phone in megabytes.

  • $n$ lines, each with two integers $d, s$ ($1 \le d, s \le 10\, 000$), the download size and storage size of an app, in megabytes.


Output one line with the maximum number of apps that can be installed. Then output one line listing the numbers of those apps, in the order that Sandra should install them. In the case that no apps can be installed, this line can be omitted.

The apps are numbered from $1$ to $n$, in the order they are given in the input. If there are multiple optimal solutions, output any one of them.

Sample Input 1 Sample Output 1
2 100
99 1
1 99
1 2
Sample Input 2 Sample Output 2
2 100
500 1
1 500