poj2014

简单题

View Code
#include <iostream>
#include
<cstdio>
#include
<cstdlib>
#include
<cstring>
using namespace std;

int m;

void input()
{
int now = m;
int d = 0;
int nowd = 0;
int maxnow = 0;
int x, y;
while (scanf("%d%d", &x, &y), !(x == -1 && y == -1))
if (now + x > m)
{
now
= x;
maxnow
= max(maxnow, now);
d
+= nowd;
nowd
= y;
}
else
{
now
+= x;
maxnow
= max(maxnow, now);
nowd
= max(nowd, y);
}
d
+= nowd;
printf(
"%d x %d\n", maxnow, d);
}

int main()
{
//freopen("t.txt", "r", stdin);
while (scanf("%d", &m), m)
{
input();
}
return 0;
}

你可能感兴趣的:(poj)