最水黑题

· · 题解

题目描述\ 距离知名的线上编程大赛Codehorses Round 2017只剩 T 毫秒啦!

Polycarp需要下载B++的编译器来参加这次比赛。文件的大小是 f 字节。

Polycarp的网络套餐能让他以每 t0 秒1字节的速度下载。这个套餐已经付过费了,它的使用也不会导致任何费用。除此以外,互联网服务的提供商额外提供了两个下载包:

以每 t1 毫秒1字节的速度下载 a1 字节,价格是 p1 “burles”(这个单词没查到,反正就是钱的单位)。\ 以每 t2 毫秒1字节的速度下载 a2 字节,价格是 p2 “burles”。\ 这些包可以任意购买。买包时,它的价格( p1 或 p2 )是提前付款的。一旦一个包被购买,它就会取代常规的网络套餐直到到达下载上限。在一个包用完后,Polycarp可以立即买新包或者调到常规的套餐(不损失时间)。一个包正在使用时,Polycarp不能再买包或者调回常规套餐。

你的任务就是找到Polycarp最少需要花多少钱才能在 T 毫秒内下载一个 f 字节的文件。

注意:因为技术原因,不管用哪种手段(常规套餐或下载包),Polycarp的下载的字节数都是整数, 即三种下载方式的下载字节数都会是整数。也就是说,Polycarp不能用常规套餐和/或下载包来分块地下载一个字节。

输入输出格式 输入格式: 第一行有三个整数 f,T 和 t0 (1 <= f,T,t0 <= 1e7),具体含义见题目描述。

第二行有第一个下载包的描述,即 a1, t1 和p1 (1 <= a1, t1 ,p1 <= 1e7),具体含义见题目描述。

第三行有第二个下载包的描述,即 a2, t2 和p2 (1 <= a2, t2 ,p2 <= 1e7),具体含义见题目描述。

输出格式: 输出Polycarp最少需要多少钱(也就是多少"burles"啦)才能在T毫秒内下载好B++编译器。无解输出-1。

说明 在样例一中,Polycarp需要买第一个下载包5次、买第二个下载包0次。他在120×8 = 960毫秒(960 <= 964)内下载了120字节(其实一共下载了26×5 = 130字节)。他总共花了8×5 = 40 "burles"。

在样例二中,Polycarp有足够的时间去下载10字节。花费的时间(10×20 = 200毫秒)等于上限。

在样例三中,Polycarp需要买第一个下载包1次,第二个下载包1次。

在样例四中,Polycarp无法按时下载。

输入输出样例\ 输入 #1复制\ 120 964 20\ 26 8 8\ 13 10 4\ 输出 #1复制\ 40\ 输入 #2复制\ 10 200 20\ 1 1 1\ 2 2 3\ 输出 #2复制\ 0\ 输入 #3复制\ 8 81 11\ 4 10 16\ 3 10 12\ 输出 #3复制\ 28\ 输入 #4复制\ 8 79 11\ 4 10 16\ 3 10 12\ 输出 #4复制\ -1\ 说明/提示\ In the first example Polycarp has to buy the first additional package 5 times and do not buy the second additional package. He downloads 120 bytes (of total 26·5=13026⋅5=130 bytes) in 120·8=960120⋅8=960 milliseconds ( 960<=964960<=964 ). He spends 8·5=408⋅5=40 burles on it.

In the second example Polycarp has enough time to download 1010 bytes. It takes 10·20=20010⋅20=200 milliseconds which equals to upper constraint on download time.

In the third example Polycarp has to buy one first additional package and one second additional package.

In the fourth example Polycarp has no way to download the file on time.

#define ll long long
using namespace std;
int main()
{
    ll f,t,t0,a1,t1,p1,a2,t2,p2,i,j;
    ll tt,ff,minn=1e18;
    std::ios::sync_with_stdio(false);//变快
    std::cin.tie(0); //标准流
    cin>>f>>t>>t0>>a1>>t1>>p1>>a2>>t2>>p2;
    if(t1>t2) swap(t1,t2),swap(a1,a2),swap(p1,p2);
    for(i=0;a1*i<f;i++){
        ff=f-i*a1;
        tt=t-i*a1*t1;
        if(ff*t2>tt && ff*t0>tt) continue;
        if(t0<=t2 || ff*t0<=tt) j=0; 
        else j=((t0*ff-tt+t0-t2-1)/(t0-t2)+a2-1)/a2;
        if(p1*i+p2*j<minn) minn=p1*i+p2*j;
    }
    if(f*t1<=t && (f+a1-1)/a1*p1<minn) minn=(f+a1-1)/a1*p1;
    if(minn==1e18) cout<<-1<<"\n";
    else cout<<minn<<"\n";
    return 0;
}

include<bits/stdc++.h>

define ll long long

using namespace std; int main() { ll f,t,t0,a1,t1,p1,a2,t2,p2,i,j; ll tt,ff,minn=1e18; std::ios::sync_with_stdio(false);//变快 std::cin.tie(0); //标准流 cin>>f>>t>>t0>>a1>>t1>>p1>>a2>>t2>>p2; if(t1>t2) swap(t1,t2),swap(a1,a2),swap(p1,p2); for(i=0;a1i<f;i++){ ff=f-ia1; tt=t-ia1t1; if(fft2>tt && fft0>tt) continue; if(t0<=t2 || fft0<=tt) j=0; else j=((t0ff-tt+t0-t2-1)/(t0-t2)+a2-1)/a2; if(p1i+p2j<minn) minn=p1i+p2j; } if(ft1<=t && (f+a1-1)/a1p1<minn) minn=(f+a1-1)/a1*p1; if(minn==1e18) cout<<-1<<"\n"; else cout<<minn<<"\n"; return 0; }