
#include <cstdio> #include <iostream> #include <cmath> #include <string> #include <cstring> #include <algorithm> #include <queue> #include <vector> #include <map> using namespace std; #define ll long long const int maxn = 5100; int t, n, A, B, L, l, r; int main() { scanf("%d", &t); int miao = t; while(t--) { scanf("%d%d%d%d", &n, &A, &B, &L); int legacy = 0, position = 0, need = 0;//legacy是剩余耐力,need是需求,position是当前位置 for(int i = 0; i<n; i++) { scanf("%d%d", &l, &r); legacy += (l-position)*B-(r-l)*A;//(上一段平底回复的)-(这一段澡泽消耗的) position = r;//把上一段澡泽的最后一个位置标记下来 if(legacy<0)//耐力不够时需要额外添加 { need -= legacy;//这时候legacy是负的,所以要减 legacy = 0; } } printf("Case #%d: %d\n", miao-t, need); } return 0; }
原文:https://www.cnblogs.com/RootVount/p/11235961.html