/*POJ 2014 Flow Layout 模拟*/ #include <iostream> using namespace std; int main() { int maxGiven; int width_in, height_in; int width_curr, height_curr; int width_max, height_max; while(1 == scanf("%d", &maxGiven)) { if(maxGiven == 0) break; width_curr = height_curr = 0; width_max = height_max = 0; while(2 == scanf("%d %d", &width_in, &height_in)) { if(width_in == -1 && height_in == -1) break; if(width_curr + width_in > maxGiven) { if(width_curr > width_max) width_max = width_curr; height_max += height_curr; //注意点! width_curr = height_curr = 0; } width_curr += width_in; if(height_in > height_curr) height_curr = height_in; } if(width_curr > width_max) //注意点! width_max = width_curr; height_max += height_curr; printf("%d x %d/n", width_max, height_max); } return 0; }