这题数据。。。
查看原帖
这题数据。。。
413301
Digital_Sunrise楼主2021/7/10 10:44

可以看到,我糊了一个很奇怪的写法

#include <bits/stdc++.h>
using namespace std;

int read(){
   int s = 0,w = 1;
   char ch = getchar();
   while(ch < '0' || ch > '9'){if(ch == '-')w = -1;ch = getchar();}
   while(ch >= '0' && ch <= '9')s = s * 10 + ch - '0',ch = getchar();
   return s * w;
}

int n,m;
int a[1000010];
int b[1000010];
map <int,int> Map; 

priority_queue <int,vector<int>,less<int> > q;
priority_queue <int,vector<int>,greater<int> > p;

signed main()
{
	n = read();
	m = read();
	for(register int i = 1;i <= n;++i)
		a[i] = read(), q.push(a[i]),p.push(a[i]),Map[a[i]] = i;
	for(register int i = 1;i <= n;++i)
		b[i] = read();
	for(register int i = 1;i <= m;++i)
	{
		register int x = q.top();///
		register int y = Map[x];///
		register int z = p.top();
		register int u = Map[z];
		register int szx = x - b[y];///
		register int akioi = b[u] - z;
		if(szx <= 0 and akioi <= 0)
			break;
		if(szx > akioi)
		{
			q.pop();
			q.push(b[y]);
			swap(a[y],b[y]);
		}
		else
		{
			p.pop();
			p.push(b[u]);
			swap(a[u],b[u]);
		}
	}
	printf("%d",q.top() - p.top());
	return 0;
}

由于当时在打比赛,就想着骗点分,连样例都没过,结果。。。

AC了

2021/7/10 10:44
加载中...