题目链接 2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest
Problem A
Problem B
Problem C
枚举第一个包的购买数量。
根据第一个包购买数量计算出如果要在规定时间内完成那么剩下那些未下载的字节数至少有几个字节需要用第二个包的速度。
由此算出第二个包的购买量(如果第二个包的速度比普通的都慢那就不考虑了),不停更新答案。
同理,枚举第二个包的购买数量再做一次即可。
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i)
typedef long long LL;
LL f, t, t0, a1, t1, p1, a2, t2, p2;
LL ans;
void solve(){
LL x = 0;
while (x <= 1e7){
++x;
LL byt = min(x * a1, f);
LL remain_f = f - byt;
LL nowt = byt * t1;
LL remain_t = t - nowt;
if (remain_f * min(t0, t2) > remain_t) continue;
if (remain_f * t0 <= remain_t){
ans = min(ans, x * p1);
continue;
}
if (t0 <= t2){
if (remain_f * t0 <= remain_t) ans = min(ans, x * p1);
continue;
}
LL num;
LL up = remain_t - remain_f * t0;
LL down = t2 - t0;
if (up % down == 0) num = up / down;
else num = up / down + 1;
LL opp = (num - 1) / a2 + 1;
ans = min(ans, x * p1 + opp * p2);
if (x * a1 * t1 >= t) break;
}
}
int main(){
cin >> f >> t >> t0;
cin >> a1 >> t1 >> p1;
cin >> a2 >> t2 >> p2;
if (f * t0 <= t) return 0 * puts("0");
ans = 9e18;
solve();
swap(a1, a2);
swap(t1, t2);
swap(p1, p2);
solve();
if (ans < 9e18) printf("%lld\n", ans);
else puts("-1");
return 0;
}
Problem D
Problem E
Problem F
Problem G
Problem H
Problem I
Problem J
Problem K
Problem L
Problem M