#include<bits/stdc++.h>
#define maxn 100010
#define all 100000LL
using namespace std;
typedef long long ll;
template<typename T> inline void read(T &x)
{
x=0;char c=getchar();bool flag=false;
while(!isdigit(c)){if(c=='-')flag=true;c=getchar();}
while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
if(flag)x=-x;
}
ll n,m,k,top,tot;
ll a[maxn],s[maxn],c[maxn],d[maxn],num[maxn],ans[maxn];
bool vis[maxn];
struct node
{
ll v,id;
}st[maxn];
bool operator <(const node &a,const node &b)
{
return a.v<b.v;
}
vector<int> ve[maxn];
priority_queue<node> q;
int main()
{
read(n),read(m),read(k);
for(int i=1;i<=n;++i)
{
read(a[i]),read(s[i]),read(c[i]),read(d[i]);
if(!d[i]) ve[all].push_back(i);
else ve[min(all,(c[i]+d[i]-1)/d[i])].push_back(i);
}
for(int i=all;i;--i)
{
ll now=m;
for(int j=0;j<ve[i].size();++j)
q.push((node){a[ve[i][j]]+s[ve[i][j]],ve[i][j]});
while(!q.empty()&&now)
{
node x=q.top();
q.pop();
if(!vis[x.id])
{
vis[x.id]=true,ans[all]+=x.v,num[x.id]++,now--;
if(c[x.id]!=1) q.push((node){a[x.id],x.id});
}
else
{
ll val=min(now,c[x.id]-num[x.id]-(i-1)*d[x.id]);
ans[all]+=x.v*val,num[x.id]+=val,now-=val;
if(c[x.id]!=num[x.id]) st[++top]=(node){a[x.id],x.id};
}
}
while(top) q.push(st[top--]);
}
while(!q.empty()) q.pop();
for(int i=1;i<=n;++i)
{
if(!num[i]) continue;
tot+=num[i];
if(num[i]==1) q.push((node){-a[i]-s[i],i});
else q.push((node){-a[i],i});
}
for(int i=all-1;i;--i)
{
ans[i]=ans[i+1];
while(!q.empty()&&tot>i*m)
{
node x=q.top();
q.pop(),x.v*=-1;
if(num[x.id]==1) ans[i]-=x.v,num[x.id]--,tot--;
else
{
ll val=min(num[x.id]-1,tot-i*m);
ans[i]-=x.v*val,num[x.id]-=val,tot-=val;
if(num[x.id]==1) q.push((node){-a[x.id]-s[x.id],x.id});
else q.push((node){-a[x.id],x.id});
}
}
}
for(int i=1,p;i<=k;++i) read(p),printf("%lld\n",ans[p]);
return 0;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 1.019 ms | 3 MB + 124 KB | Accepted | Score: 4 | 显示更多 |
Testcase #2 | 1.054 ms | 3 MB + 128 KB | Accepted | Score: 4 | 显示更多 |
Testcase #3 | 1.039 ms | 3 MB + 128 KB | Accepted | Score: 4 | 显示更多 |
Testcase #4 | 972.06 us | 3 MB + 200 KB | Accepted | Score: 4 | 显示更多 |
Testcase #5 | 970.79 us | 3 MB + 200 KB | Accepted | Score: 4 | 显示更多 |
Testcase #6 | 976.22 us | 3 MB + 200 KB | Accepted | Score: 4 | 显示更多 |
Testcase #7 | 801.58 us | 3 MB + 116 KB | Accepted | Score: 4 | 显示更多 |
Testcase #8 | 800.34 us | 3 MB + 116 KB | Accepted | Score: 4 | 显示更多 |
Testcase #9 | 804.38 us | 3 MB + 116 KB | Accepted | Score: 4 | 显示更多 |
Testcase #10 | 782.93 us | 3 MB + 116 KB | Accepted | Score: 4 | 显示更多 |
Testcase #11 | 812.25 us | 3 MB + 120 KB | Accepted | Score: 4 | 显示更多 |
Testcase #12 | 843.4 us | 3 MB + 128 KB | Accepted | Score: 4 | 显示更多 |
Testcase #13 | 854.65 us | 3 MB + 124 KB | Accepted | Score: 4 | 显示更多 |
Testcase #14 | 867.91 us | 3 MB + 128 KB | Accepted | Score: 4 | 显示更多 |
Testcase #15 | 846.12 us | 3 MB + 128 KB | Accepted | Score: 4 | 显示更多 |
Testcase #16 | 1.351 ms | 3 MB + 208 KB | Accepted | Score: 4 | 显示更多 |
Testcase #17 | 1.427 ms | 3 MB + 224 KB | Accepted | Score: 4 | 显示更多 |
Testcase #18 | 1.405 ms | 3 MB + 208 KB | Accepted | Score: 4 | 显示更多 |
Testcase #19 | 1.467 ms | 3 MB + 224 KB | Accepted | Score: 4 | 显示更多 |
Testcase #20 | 1.469 ms | 3 MB + 224 KB | Accepted | Score: 4 | 显示更多 |
Testcase #21 | 75.831 ms | 12 MB + 436 KB | Accepted | Score: 4 | 显示更多 |
Testcase #22 | 50.94 ms | 12 MB + 548 KB | Accepted | Score: 4 | 显示更多 |
Testcase #23 | 84.301 ms | 12 MB + 440 KB | Accepted | Score: 4 | 显示更多 |
Testcase #24 | 55.312 ms | 12 MB + 924 KB | Accepted | Score: 4 | 显示更多 |
Testcase #25 | 55.637 ms | 12 MB + 928 KB | Accepted | Score: 4 | 显示更多 |