QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | 提交记录ID | 题目 | Hacker | Owner | 结果 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|
#1166 | #268770 | #7646. 优惠购物 | DaiRuiChen007 | _set_ | Failed. | 2024-11-11 18:29:01 | 2024-11-11 18:29:01 |
详细
Extra Test:
Invalid Input
input:
4 46534 693282718 810866627 861972810 776818440 213954599 46541461 891682310 704331958 598400995 857297960 973103126 529732187 521526752 896860467 973344100 134652401 321466028 35323911 129180794 269865515 608297960 838178787 808675328 519657963 368274217 869364103 604425120 301385668 922432631 6948...
output:
result:
FAIL b[i]>a[i]
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#268770 | #7646. 优惠购物 | _set_ | 100 ✓ | 179ms | 11572kb | C++17 | 1.1kb | 2023-11-28 20:58:19 | 2023-12-28 11:04:42 |
answer
//xhz.cpp
#include<bits/stdc++.h>
using namespace std;
int n,m,c,a[1000003],b[1000003];
void solve(){
cin>>n>>m>>c;
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<n;i++)cin>>b[i];
map<int,long long>mp;
mp[0]=m;
long long ans=0;
for(int i=0;i<n;i++){
int tmp=b[i];
while(mp.size()){
auto it=mp.begin();
if((it->first+1)*(it->second)<=b[i]){
ans+=it->first*it->second;
b[i]-=(it->first+1)*(it->second);
mp.erase(it);
}else{
int t=it->first;
it->second-=b[i]/(t+1)+1;
ans+=b[i]/(t+1)*t;
b[i]%=(t+1);
int f=c-(a[i]-tmp+b[i])%c;
if(c-f-b[i]<=0){
ans+=c-f;
b[i]-=c-f;
mp[t+f-c]++;
}else if(t-b[i]<=f||b[i]+f>tmp){
ans+=b[i];
mp[t-b[i]]++;b[i]=0;
}else mp[t]++;
if(!it->second)mp.erase(t);
break;
}
}tmp-=b[i];
tmp=a[i]-tmp;
ans+=tmp;
mp[0]+=tmp/c;
if(tmp%c!=0&&(tmp/c+1)*c<=a[i]){
mp[(tmp/c+1)*c-tmp]++;
tmp=(tmp/c+1)*c;
}mp[c]+=(a[i]-tmp)/c;
}
cout<<ans<<'\n';
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T;cin>>T;
while(T--)solve();
}