QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#44587 | #4585. Greedy Knapsack | eyiigjkn | WA | 2ms | 3776kb | C++14 | 810b | 2022-08-19 14:40:30 | 2022-08-19 14:40:33 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int w[100010],v[100010];
priority_queue<pair<ll,ll>,vector<pair<ll,ll>>> que;
vector<pair<ll,ll>> vec;
int main()
{
int n,maxw=0;
ll m;
cin>>n>>m;
for(int i=1;i<=n;i++) scanf("%d",&w[i]),maxw=max(maxw,w[i]);
for(int i=1;i<=n;i++) scanf("%d",&v[i]);
ll L=max(m-maxw+1,1ll),R=m,ans=0;
for(int i=1;i<=n;i++)
{
if(w[i]<=L) L-=w[i],R-=w[i],ans+=v[i];
else if(w[i]<=R) que.emplace(R-w[i],ans+v[i]),R=w[i]-1;
while(!que.empty() && que.top().first>=w[i])
{
auto p=que.top();que.pop();
vec.emplace_back(w[i]-1,p.second);
vec.emplace_back(p.first-w[i],p.second+v[i]);
}
for(auto j:vec) que.push(j);
}
for(;!que.empty();que.pop()) ans=max(ans,que.top().second);
cout<<ans<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3776kb
input:
5 10 10 1 2 3 4 1 1 1 1 1
output:
4
result:
wrong answer 1st lines differ - expected: '3', found: '4'