QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#44587#4585. Greedy KnapsackeyiigjknWA 2ms3776kbC++14810b2022-08-19 14:40:302022-08-19 14:40:33

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-08-19 14:40:33]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3776kb
  • [2022-08-19 14:40:30]
  • 提交

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'