bzoj3280 Little R's troubles

Source: Internet
Author: User

Description Small R recently encountered a big trouble, his program design Hang branch. So he had to find Cheng teacher plead. The good Cheng teacher promised not to hang him, but asked Little R to help him solve a difficult problem together. The problem is that Cheng recently had to conduct an evil experiment to prove P=NP, the experiment lasted n days, the first day I need A[i] a graduate student to bring him bricks. After all, graduate students are also people, so the use of graduate students need money, witty Cheng teacher has contacted M University, J University of L[j] a graduate student, while hiring a graduate student in this university need p[j] yuan money. Originally Cheng teacher filled with joy thought, so pick the cheapest max{a[i]} A graduate student hired, you can complete the experiment; The result did not expect, because he asked graduate students to work 25 hours a day not to eat to sleep in the toilet drink water talk cough sneeze breathing air, So all the graduate students who came down to his brick one day would go to near-death status. There is no doubt that a graduate student of near-death status can no longer work. But the witty teacher early contact with the K Home Hospital, the first hospital to heal a dying graduate students need d[i] days, and need q[i] yuan money.

Now, Cheng the teacher wants to know, at least how much money, can be in this n days to meet the daily needs? If this is not possible, please output "impossible". Note that because Cheng teacher's conscience is so bad, he can not send the dying graduate student to the hospital!

Input

The subject contains multiple sets of data; The first line is a number T (t<=11), which represents the number of data groups and the following T-group data.
For each set of data, the first row of three numbers, n,m,k;
The following row n number, representing A[1]...a[n]
Then a line of 2m number, indicating l[1],p[1]...l[n],p[n]
Then a line of 2k number, indicating d[1],q[1]...d[n],q[n]

Output

For each set of data, output a row in a sample format, with two numbers representing the first group of data and the minimum amount of money.

Sample Input2
3 2 1
10 20 30
40 90 15 100
1 5
3 2 1
10 20 30
40 90 15 100
2 5
Sample OutputCase 1:4,650
Case 2:impossible
HINT

Example explanation: Buy 90 dollars of the 40 graduate students, and then buy 10 100 yuan. In this way, the first day of the use of 10 people to the hospital, then they can continue to use the third day, and the next day and the third day with the new graduate students to make up, so altogether need to spend 40*90 + 10*100 + 5*10 = 4650 yuan.

Data size:

For each set of data in 30% of the data,

Satisfies the n<=5,m,k<=2, the remaining number is less than or equal to 100 or

n<=10,m,k<=10, the remaining numbers are less than or equal to 20.

For 100% of data

N,m,k<=50, the remaining numbers are less than or equal to 100.

The problem is the same as the one in the network flow 24 question.
#include <cstdio> #include <iostream> #include <cstring> #include <cstdlib> #include < algorithm> #include <cmath> #include <queue> #include <deque> #include <set> #include <map > #include <ctime> #define LL long long#define INF 0x3fffffff#define pa pair<int,int> #define Pi    3.1415926535897932384626433832795028841971#define S 0#define T 1001#define N 1010using namespace Std;inline LL Read () {    LL X=0,f=1;char Ch=getchar (); while (ch< ' 0 ' | |    Ch> ' 9 ') {if (ch== '-') F=-1;ch=getchar ();}    while (ch>= ' 0 ' &&ch<= ' 9 ') {x=x*10+ch-' 0 '; Ch=getchar ();} return x*f;} struct Edge{int to,next,v,from,c;} E[100*n];int head[n],dist[n],q[n],from[n];bool mrk[n];int n,m,k,cnt,ans;inline void ins (int u,int v,int w,int c) {E[++c    Nt].to=v;    E[cnt].v=w;    E[cnt].c=c;    E[cnt].from=u;    E[cnt].next=head[u]; head[u]=cnt;}    inline void Insert (int u,int v,int w,int c) {ins (u,v,w,c); Ins (v,u,0,-c);} inline bool Spfa () {for (int i=0;i<=t;i++) Dist[i]=inf;    int t=0,w=1;    Dist[s]=0;q[0]=s;mrk[s]=1;        while (t!=w) {int now=q[t++];if (t==1005) t=0;                for (int i=head[now];i;i=e[i].next) if (e[i].v&&dist[now]+e[i].c<dist[e[i].to]) {                DIST[E[I].TO]=DIST[NOW]+E[I].C;                From[e[i].to]=i;                    if (!mrk[e[i].to]) {mrk[e[i].to]=1;                    q[w++]=e[i].to;                if (w==1005) w=0;    }} mrk[now]=0; } return Dist[t]!=inf;}    inline void Mcf () {int x=inf;    for (int i=from[t];i;i=from[e[i].from]) x=min (X,E[I].V);        for (int i=from[t];i;i=from[e[i].from]) {e[i].v-=x;        E[i^1].v+=x;    ANS+=X*E[I].C;    }}inline void work (int dfn) {memset (head,0,sizeof (head));    cnt=1;ans=0;    N=read (); M=read (); K=read ();        for (int i=1;i<=n;i++) {int x=read ();        Insert (s,i,x,0);        Insert (i+n,t,x,0); if (i!=n) INSERT (i+n,i+n+1,inf,0);        } for (int i=1;i<=m;i++) {int x=read (), Y=read ();    Insert (0,n+1,x,y);        } for (int i=1;i<=k;i++) {int x=read (), Y=read ();    for (int j=1;j<=n;j++) if (j+x+1<=n) insert (j,j+x+1+n,inf,y);    } printf ("Case%d:", DFN);    while (SPFA ()) MCF ();    BOOL mrk=0;            for (int i=2;i<=cnt;i+=2) if (E[I].TO==T&AMP;&AMP;E[I].V) {printf ("impossible\n");        Return } printf ("%d\n", ans);}    int main () {int tt=read (); for (int. i=1;i<=tt;i++) work (i);}

bzoj3280 Little R's troubles

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.