aboutsummaryrefslogtreecommitdiff
path: root/c/128_Florencia.cpp
blob: 32e221a226594f86334893a141a855d0424ed7ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>

using namespace std;

int main() {
	int size;
	int sides, parts, length;
	int totalPieces, rest, remainingSize;
	int impossibleFlag;
	cin >> size; // Primera lectura del tamaƱo fuera del bucle para primera comprobaciĆ³n
	while (size != -1) {
		totalPieces = 1;
		rest = 0;
		remainingSize = size;
		impossibleFlag = 0;
		cin >> sides;
		while (sides != -1) {
			cin >> parts;
			cin >> length;
			if (length > size && !impossibleFlag) {
				cout<<"IMPOSIBLE\n";
				impossibleFlag = 1;
			}
			else if (!impossibleFlag) {
				for (int i = 0; i < sides * parts; i++ ) {
					if (remainingSize >= length)
						remainingSize -= length;
					else {
						rest += remainingSize;
						remainingSize = size - length;
						totalPieces++;
					}
				}
			}
			cin >> sides;
		}
		if (remainingSize != size)
			rest += remainingSize;
		else { // Se ejecuta cuando no se ha usado nada de varilla (remainingSize nunca vuelve a ser size).
			totalPieces = 0;
			rest = 0;
		}
		if (!impossibleFlag)
			cout<<totalPieces<<" "<<rest<<endl;
		cin >> size;
	}
}