#include #include using namespace std; int main() { int n, m, i; long long D[11][1101]; while (cin>>n>>m) { int flag[11] = {};//def vector blood int minus = 0;//max of attack int *blo = new int[n]; int *def = new int[n]; for (i=0; i>blo[i]>>def[i]; flag[def[i]] = max(blo[i], flag[def[i]]); } int *sto = new int[m]; int *att = new int[m]; for (i=0; i>sto[i]>>att[i]; minus = max(att[i], minus); } for (i=0; i<=10; i++)//def { if (flag[i]) { if (minus<=i) { for (int j=1; j<=flag[i]; j++)//blood { D[i][j] = -1; } } else { D[i][0] = 0; for (int j=1; j<=flag[i]; j++)//blood { D[i][j] = 1e17; for (int k=0; k