QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#463049 | #7646. 优惠购物 | Kim | 0 | 309ms | 19372kb | C++14 | 1.6kb | 2024-07-04 12:16:29 | 2024-07-04 12:16:29 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#ifdef LOCAL
void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
const int MAXN = 1000005;
const int inf=1000000500ll;
const long long oo =1000000000000000500ll;
const int MOD = (int)1e9+7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int> pi;
int n,m,C;
int A[MAXN];
int B[MAXN];
int f(int K){ // we are forced to use get exactly K stacks of vouchers for free.
int ans=0;
int vou=m;
for(int i=1;i<=n;i++){
int num=A[i]/C;
int ai=A[i];
if(num<=K){
K-=num;
vou+=num;
ans+=num*C;
ai-=num*C;
} else{
vou+=K;
ans+=K*C;
num-=K;
ai-=K*C;
K=0;
}
int vouuse=min({vou,ai});
vou-=vouuse;
ans+=ai-vouuse;
}
if(K>0)return oo;
else return ans;
}
void solve(){
cin>>n>>m>>C;
for(int i=1;i<=n;i++)cin>>A[i];
for(int i=1;i<=n;i++)cin>>B[i];
int lower=0,upper=0;
for(int i=1;i<=n;i++){
upper+=A[i]/B[i];
}
while(upper-lower+1>=3){
int len=(upper-lower+1);
int c1=lower+len/3;
int c2=upper-len/3;
if(f(c1)<f(c2)){
upper=c2;
} else if(f(c1)>f(c2)){
lower=c1;
} else{
lower=c1;
upper=c2;
}
}
int ans=oo;
for(int i=lower;i<=upper;i++)ans=min(ans,f(i));
cout<<ans<<"\n";
}
int32_t main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
int tc;cin>>tc;
while(tc--)solve();
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
5 10 9 8 10 5 1 2 10 9 2 9 8 8 5 3 1 1 7 2 2 1 3 0 10 1 5 3 2 6 10 5 10 1 4 8 1 1 2 5 6 2 3 1 3 6 1 10 6 10 5 4 9 5 4 10 8 5 2 4 2 4 2 5 1 1 7 5 0 0 10 5 10 6 2 7 4 3 8 10 5 5 4 1 0 6 3 3 5 4 5 0 0 10 6 12 6 8 7 3 1 4 10 2 9 10 0 3 1 3 1 3 1 0 4 7
output:
result:
Subtask #2:
score: 0
Wrong Answer
Test #4:
score: 0
Wrong Answer
time: 309ms
memory: 19372kb
input:
1 1000000 75424149 4 15519624 393474467 66570532 20552964 884794646 633920424 885627436 891022137 207531470 263467015 853563838 909020263 225156643 843397191 555130236 28501962 70380880 400094075 351542363 118716292 772000502 495729611 777038576 845271464 346378405 179347308 90713310 683636539 92786...
output:
500014427858585
result:
wrong answer 1st lines differ - expected: '400011543086868', found: '500014427858585'
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Runtime Error
Test #24:
score: 0
Runtime Error
input:
600 10 21 2 1434256 1792820 8964100 10756920 6454152 717128 9681228 7529844 7171280 10398356 1075692 1075692 1434256 10039792 358564 717128 717128 5737024 3227076 1792820 10 5 4 5500368 6875460 4125274 687544 5500368 4469049 4125276 2750183 9969416 5156593 4469049 3781503 687546 0 1718865 343773 0 2...
output:
result:
Subtask #7:
score: 0
Skipped
Dependency #6:
0%
Subtask #8:
score: 0
Skipped
Dependency #6:
0%
Subtask #9:
score: 0
Skipped
Dependency #2:
0%