QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#710352#8548. China Convex Polygon ContestWolam#WA 13ms3604kbC++201.3kb2024-11-04 19:32:232024-11-04 19:32:23

Judging History

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

  • [2024-11-04 19:32:23]
  • 评测
  • 测评结果:WA
  • 用时:13ms
  • 内存:3604kb
  • [2024-11-04 19:32:23]
  • 提交

answer

#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
using ll = long long;
const int maxn = 1e5 + 10;
ll a[maxn],b[maxn];
void solve(void)
{
	ll n,m;
	cin>>n>>m;
	vector<pair<ll,ll>> vec;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		vec.emplace_back(a[i],2);
	}
	for(int i=1;i<=n;i++)
	{
		cin>>b[i];
	}
	sort(b+1,b+n+1);
	for(int i=1;i<=n;i++)
	{
		b[i]+=b[i-1];
		if(b[i]<=m)
		{
			vec.emplace_back(b[i],1);
		}
	}
	vec.emplace_back(m,2);
	sort(vec.begin(),vec.end(),greater<pair<ll,ll>>());
	priority_queue<ll,vector<ll>,less<ll>> pq;
	ll last=-1,ans=0,vis=0;
	for(auto [pos,c] : vec)
	{
		//cerr<<"###"<<pos<<" "<<c<<endl;
		if(c==2)
		{
			if(~last)
			{
				if(vis&&!pq.empty())
				{
					ll mx=pq.top();
					pq.pop();
					pq.emplace(mx+last-pos);
				}
				else
				{
					pq.emplace(last-pos);
				}
			}
			last=pos;
			vis=0;
		}
		else
		{
			if(!pq.empty())
			{
				if(last-pos>pq.top())
				{
					ans+=last-pos;
					last=pos;
					vis=1;
				}
				else
				{
					ans+=pq.top();
					pq.pop();
				}
			}
			else
			{
				ans+=last-pos;
				last=pos;
				vis=1;
			}
		}
	}
	cout<<ans<<endl;
}
int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3540kb

input:

3
3 10
1 5 9
1 2 3
3 10
1 5 9
1 1 4
3 10
1 5 9
1 5 10

output:

9
9
7

result:

ok 3 number(s): "9 9 7"

Test #2:

score: -100
Wrong Answer
time: 13ms
memory: 3604kb

input:

10000
9 879847766
125098132 150509852 181700303 196375322 519766842 560891576 609151480 721527163 805167083
99031467 66330518 6283986 21388462 41109537 83628243 116141243 144052767 192448599
8 30
5 12 16 19 20 23 25 27
3 1 1 4 2 8 2 3
8 30
4 10 13 16 17 20 23 27
6 3 1 2 3 4 7 2
7 586479012
37693706 ...

output:

761161856
27
27
548785306
28
871468685
26
754736418
811536173
712299669
533766997
759475944
28
27
28
809845999
27
26
26
727698126
27
26
28
28
28
27
27
27
28
819730903
755946410
27
26
28
754337036
876148480
537594597
782750950
910829331
26
26
793886583
26
26
29
488557236
25
26
618111955
28
25
8328741...

result:

wrong answer 1st numbers differ - expected: '858888761', found: '761161856'