1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <iostream> 5 #include <queue> 6 using namespace std; 7 typedef long long LL; 8 9 const int MAXV = 10010; 10 const int MAXE = MAXV * 4; 11 12 int head[MAXV], ecnt; 13 int to[MAXE], next[MAXE], cost[MAXE]; 14 15 void init(int n) { 16 memset(head, -1, n * sizeof(int)); 17 ecnt = 0; 18 } 19 20 void add_edge(int u, int v, int c) { 21 to[ecnt] = v; cost[ecnt] = c; next[ecnt] = head[u]; head[u] = ecnt++; 22 } 23 24 int dis[MAXV]; 25 26 void solve(int n) { 27 memset(dis, 0, n * sizeof(int)); 28 for(int u = n - 1; u >= 0; --u) { 29 for(int p = head[u]; ~p; p = next[p]) { 30 int &v = to[p]; 31 dis[u] = max(dis[u], dis[v] + cost[p]); 32 } 33 } 34 } 35 36 int dates[MAXV], earning[MAXV]; 37 int start[MAXV], finish[MAXV], rates[MAXV]; 38 int tmp[MAXV], tcnt; 39 int T, n, m; 40 41 int hash(int x) { 42 return lower_bound(tmp, tmp + tcnt, x) - tmp; 43 } 44 45 int main() { 46 scanf("%d", &T); 47 for(int t = 1; t <= T; ++t) { 48 scanf("%d%d", &n, &m); 49 for(int i = 0; i < n; ++i) scanf("%d%d", &dates[i], &earning[i]); 50 for(int i = 0; i < m; ++i) scanf("%d%d%d", &start[i], &finish[i], &rates[i]); 51 52 tcnt = 0; 53 for(int i = 0; i < n; ++i) tmp[tcnt++] = dates[i]; 54 for(int i = 0; i < m; ++i) 55 tmp[tcnt++] = start[i], tmp[tcnt++] = finish[i]; 56 sort(tmp, tmp + tcnt); 57 tcnt = unique(tmp, tmp + tcnt) - tmp; 58 59 init(tcnt); 60 for(int i = 1; i < tcnt; ++i) add_edge(i - 1, i, 0); 61 for(int i = 0; i < m; ++i) add_edge(hash(start[i]), hash(finish[i]), rates[i]); 62 63 solve(tcnt); 64 LL ans = 0; 65 for(int i = 0; i < n; ++i) { 66 ans += LL(earning[i]) * dis[hash(dates[i])]; 67 } 68 69 printf("Case #%d:\n", t); 70 printf("%I64d.%02I64d\n", ans / 100, ans % 100); 71 } 72 }