50229. Cup and Pool
難度:2/51
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
// #define max(a,b) ((a)>(b)?(a):(b))
// #define min(a,b) ((a)<(b)?(a):(b))
typedef struct{
int cap;
int vol;
} cup;
int main(){
int k; cup arr[20005];
scanf("%d", &k);
for(int i = 0; i < k; i++) scanf("%d", &arr[i].cap);
for(int i = 0; i < k; i++) scanf("%d", &arr[i].vol);
int from, to;
while(scanf("%d %d", &from, &to) != EOF){
if(from == k) arr[to].vol = arr[to].cap;
else if(to == k) arr[from].vol = 0;
else{
if(arr[from].vol + arr[to].vol > arr[to].cap){
arr[from].vol -= (arr[to].cap - arr[to].vol);
arr[to].vol = arr[to].cap;
}
else{
arr[to].vol += arr[from].vol;
arr[from].vol = 0;
}
}
}
for(int i = 0; i < k; i++){
printf("%d%c", arr[i].vol, (i == k - 1) ? '\n' : ' ');
}
}