Skip to content

Instantly share code, notes, and snippets.

@prongs
Created October 16, 2012 19:27
Show Gist options
  • Save prongs/3901416 to your computer and use it in GitHub Desktop.
Save prongs/3901416 to your computer and use it in GitHub Desktop.
#define s(n) scanf("%d", &n)
#define MIN(a,b) ((a<b)?a:b)
#define MAX(a,b) ((a>b)?a:b)
#include <iostream>
#include <string.h>
struct W
{
int L; int C;
};
int T,N,M;
W Fs[100], Is[100];
int diff[100];
int maxdiff;
int main(int argc, char const *argv[])
{
s(T);
while(T--)
{
scanf("%d %d", &N,&M);
memset(diff, 0, sizeof(diff));
for (int i = 0; i < N; ++i)
{
scanf("%d %d", &(Is+i)->C, &(Is+i)->L);
diff[Is[i].L-1]-=Is[i].C;
}
for (int i = 0; i < M; ++i)
{
scanf("%d %d", &(Fs+i)->C, &(Fs+i)->L);
diff[Fs[i].L-1]+=Fs[i].C;
}
maxdiff=0;
for (int i = 0; i < 100; ++i)
maxdiff=(diff[i]<0)?maxdiff:maxdiff+diff[i];
printf("%d\n", maxdiff);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment