Submission details
Task:Drink Responsibly
Sender:Game of Nolife
Submission time:2015-11-25 18:06:24 +0200
Language:C++
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.05 sdetails
#2ACCEPTED0.05 sdetails
#3ACCEPTED0.05 sdetails
#4ACCEPTED0.06 sdetails
#5ACCEPTED0.06 sdetails
#6ACCEPTED0.05 sdetails

Code

#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef long double ld;

string na[10];
int str[10];
int sz[10];
int co[10];
int vo[10];

int ct[10];

int m,u;

char ok[2020][22010];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//cout<<sizeof(ok)<<endl;
	ld m_d,u_d;
	cin>>m_d>>u_d;
	m=m_d*100.0+0.1;
	u=u_d*60.0+0.1;
	int d;
	cin>>d;
	//cout<<m<<" "<<u<<endl;
	for (int i=0;i<d;i++){
		cin>>na[i];
		cin>>str[i];
		string ss;
		cin>>ss;
		if (ss[2]=='1') sz[i]=6;
		if (ss[2]=='2') sz[i]=3;
		if (ss[2]=='3') sz[i]=2;
		ld co_d;
		cin>>co_d;
		co[i]=co_d*100.0+0.1;
		vo[i]=str[i]*sz[i]*10;
		//cout<<co[i]<<" "<<vo[i]<<endl;
		if (co[i]==0&&vo[i]==0&&m==0&&u==0){
			cout<<na[i]<<" "<<1<<endl;
			return 0;
		}
	}
	if (m==0&&u==0){
		cout<<"IMPOSSIBLE"<<endl;
		return 0;
	}
	ok[0][0]=1;
	for (int i=0;i<=m;i++){
		for (int ii=0;ii<=u;ii++){
			if (ok[i][ii]){
				for (int j=0;j<d;j++){
					ok[i+co[j]][ii+vo[j]]=1;
				}
			}
		}
	}
	if (!ok[m][u]){
		cout<<"IMPOSSIBLE"<<endl;
		return 0;
	}
	else{
		while (m>0||u>0){
			for (int j=0;j<d;j++){
				if (co[j]>0||vo[j]>0){
					if (m-co[j]>=0&&u-vo[j]>=0&&ok[m-co[j]][u-vo[j]]){
						m-=co[j];
						u-=vo[j];
						ct[j]++;
						break;
					}
				}
			}
		}
		for (int i=0;i<d;i++){
			if (ct[i]>0){
				cout<<na[i]<<" "<<ct[i]<<endl;
			}
		}
	}
}

Test details

Test 1

Verdict: ACCEPTED

input
3.93 19.0 8
punkipa 4 1/1 0.27
deadpony 5 1/2 0.59
vagabond 3 1/1 0.27
thisislager 3 1/2 0.51
...

correct output
bomber 1
kronenbourg 3
vagabond 2
vodka 2

user output
deadpony 4
bomber 1
kronenbourg 3

Test 2

Verdict: ACCEPTED

input
3.59 17.0 8
punkipa 6 1/3 0.41
deadpony 6 1/1 0.63
vagabond 6 1/3 0.97
thisislager 1 1/3 0.08
...

correct output
punkipa 4
vagabond 1
vodka 2

user output
punkipa 7
thisislager 9

Test 3

Verdict: ACCEPTED

input
3.14 19.5 8
punkipa 6 1/3 0.01
deadpony 3 1/2 0.34
vagabond 6 1/3 0.85
thisislager 3 1/3 0.66
...

correct output
bomber 1
fiveamred 4
kronenbourg 1
vagabond 1
vodka 1

user output
punkipa 4
vagabond 1
bomber 1
kronenbourg 1
vodka 1

Test 4

Verdict: ACCEPTED

input
9.61 20.0 8
punkipa 1 1/2 0.63
deadpony 2 1/3 0.49
vagabond 2 1/3 0.80
thisislager 3 1/1 0.12
...

correct output
bomber 2
fiveamred 5
kronenbourg 2
vagabond 2
vodka 4

user output
punkipa 9
deadpony 1
vagabond 2
thisislager 3
kronenbourg 1
...

Test 5

Verdict: ACCEPTED

input
6.24 16.1 8
punkipa 6 1/3 0.48
deadpony 3 1/3 0.09
vagabond 7 1/1 0.04
thisislager 1 1/2 0.76
...

correct output
IMPOSSIBLE

user output
IMPOSSIBLE

Test 6

Verdict: ACCEPTED

input
5.84 20.0 8
punkipa 5 1/2 0.73
deadpony 4 1/1 0.94
vagabond 5 1/3 0.01
thisislager 5 1/2 0.62
...

correct output
deadpony 2
fiveamred 4
vodka 8

user output
punkipa 8