QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#269947 | #7144. Candies | ddl_VS_pigeon# | WA | 1ms | 3608kb | C++17 | 1.2kb | 2023-11-30 12:02:23 | 2023-11-30 12:02:24 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <functional>
#include <array>
#include <vector>
#include <queue>
using namespace std;
using ll = long long;
void solve(){
int n,m,x,y;
cin >> n >> m >> x >> y;
vector<ll> a(n);
for(int i=0;i<n;i++){
cin >> a[i];
}
int freeV = max(y-(x-1),0);
y -= freeV;
a[0] += freeV;
auto check = [&](int exv)->ll {
ll ret = a[0];
priority_queue<ll,vector<ll>,greater<ll>> pq;
pq.push(a[0]+exv);
for(int i=1;i<n;i++){
pq.push(a[i]);
}
for(int i=0;i<m;i++){
ll v = pq.top();
pq.pop();
if(v==ret) ret += x;
pq.push(v+x);
}
return ret;
};
ll baseAns = check(0);
int l = 0;
int r = y;
ll ans = 0;
while(l<=r){
int mid = (l+r)>>1;
ll cv = check(mid);
if(cv<baseAns){
r = mid-1;
}else{
l = mid+1;
ans = cv;
}
}
cout << ans << '\n';
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int T;
// cin >> T;
T = 1;
while(T--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3608kb
input:
2 1 2 2 1 2
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3524kb
input:
10 9 4 3 19 32 11 1 3 3 3 12 17 34
output:
19
result:
wrong answer 1st numbers differ - expected: '22', found: '19'