每天生产一堆雪,每天有一个温度,所有雪会融化该温度的体积.
问你每天融化多少雪.
每天,把当天的雪,当作是第一天就已经存在的雪放入multiset,然后遍历,如果包括上这一天及之前的所有温度和都不能满足的雪体积,是需要在今天融化完毕的,直接erase掉.其他的,就可以承受今天的融化量,直接乘以数量即可.
#include <iostream>
#include <set>
using namespace std;
#define debug(x) std::cerr << #x << " = " << (x) << std::endl
typedef long long LL;
const int MAXN = 1e5+17;
LL a[MAXN],t[MAXN];
int main(int argc ,char const *argv[])
{
#ifdef noob
freopen("Input.txt","r",stdin);freopen("Output.txt","w",stdout);
#endif
int n;
cin>>n;
multiset<LL > s;
for (int i = 0; i < n; ++i)
{
cin>>a[i];
}
for (int i = 0; i < n; ++i)
{
cin>>t[i];
}
LL sum = 0,ad=0;
for (int i = 0; i < n; ++i)
{
s.insert(sum+a[i]);
LL sump = sum+t[i];
LL x = 0,ans=0;
while(!s.empty())
{
set<LL > :: iterator it = s.begin();
if(*it>=sump)
break;
x++,ans+=(*it)-sum;
s.erase(it);
}
ans+=(i+1-ad-x)*t[i];
ad+=x;
sum=sump;
cout<<ans<<" ";
}
return 0;
}
我觉得这题不很容易,900人题还是让我花了一个小时左右的…
好菜啊…