1 #include <bits/stdc++.h> 2 #define _for(i,a,b) for(int i = (a);i < (b);i ++) 3 #define pb push_back 4 #define ll long long int 5 6 using namespace std; 7 8 ll N; 9 ll S1,V1,S2,V2; 10 ll rnt = 0; 11 12 int kase = 1; 13 void solve() 14 { 15 ll sz = min(N/S1,N/S2); 16 if(sz<=39396) 17 { 18 int md; 19 sz == N/S1 ? md = 0:md = 1; 20 if(md) 21 { 22 _for(i,0,sz+1) 23 { 24 ll tmrnt = 0; 25 ll tmN = N; 26 tmrnt += i*V2; 27 tmN -= i*S2; 28 tmrnt += tmN/S1*V1; 29 rnt = max(tmrnt,rnt); 30 } 31 } 32 else 33 { 34 _for(i,0,sz+1) 35 { 36 ll tmrnt = 0; 37 ll tmN = N; 38 tmrnt += i*V1; 39 tmN -= i*S1; 40 tmrnt += tmN/S2*V2; 41 rnt = max(tmrnt,rnt); 42 } 43 } 44 } 45 else 46 { 47 if(S2*V1>S1*V2) 48 { 49 _for(i,0,S1) 50 { 51 ll tmrnt = 0; 52 ll tmN = N; 53 tmrnt += i*V2; 54 tmN -= i*S2; 55 tmrnt += tmN/S1*V1; 56 rnt = max(tmrnt,rnt); 57 } 58 } 59 else 60 { 61 _for(i,0,S2) 62 { 63 ll tmrnt = 0; 64 ll tmN = N; 65 tmrnt += i*V1; 66 tmN -= i*S1; 67 tmrnt += tmN/S2*V2; 68 rnt = max(tmrnt,rnt); 69 } 70 } 71 } 72 printf("Case #%d: %lld ",kase++,rnt); 73 } 74 75 int main() 76 { 77 int T; 78 scanf("%d",&T); 79 while(T--) 80 { 81 rnt = 0; 82 scanf("%lld%lld%lld%lld%lld",&N,&S1,&V1,&S2,&V2); 83 solve(); 84 } 85 return 0; 86 }
要用long long啊!不然32位边界会溢出的!