Logo Wy Online Judge

WyOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#27#196#5. 「WyOJ Round 1」炽 · 踏浪而歌__vector____vector__Success!2025-04-18 07:52:522025-04-18 07:52:54

详细

Extra Test:

Wrong Answer
time: 4ms
memory: 5484kb

input:

2
50 64

output:

64
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1...

result:

wrong output format Expected integer, but "hacked" found

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#196#5. 「WyOJ Round 1」炽 · 踏浪而歌__vector__976436ms16652kbC++231.3kb2025-04-18 07:52:312025-04-18 07:53:26

answer

#include<iostream>
#include<vector>
#include<set>
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
const int N=1e6+10;
int n,sum,res,a[N],b[N];
set <int> sa;
set <pii> sb;
vector <pii> rv;
bool check(int x,int y)
{
	sb.erase({a[x],x}),sb.insert({a[x]-1,x}); 
	if(y!=x) sb.erase({a[y],y}),sb.insert({a[y]-1,y});
	bool rf=(max((*prev(sb.end())).fi,(sum-(x!=y))/2)<=res-1);
	sb.erase({a[x]-1,x}),sb.insert({a[x],x});
	if(y!=x) sb.erase({a[y]-1,y}),sb.insert({a[y],y});
	return rf;
}
void del(int x,int y)
{
	res--,sum-=((x!=y)+1),rv.pb({x,y}),sb.erase({a[x],x}),a[x]--;
	if(a[x]) sb.insert({a[x],x});
	else sa.erase(x);
	if(y!=x)
	{
		sb.erase({a[y],y}),a[y]--;
		if(a[y]) sb.insert({a[y],y});
		else sa.erase(y);
	}
}
int main()
{
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i],sum+=a[i];
		if(a[i]) sa.insert(i),sb.insert({a[i],i});
	}
	if(sum==114)puts("hacked");
	res=max((*prev(sb.end())).fi,(sum+1)/2),cout<<res<<'\n';
	while(sa.size())
	{
		auto it=sa.begin(); int x=*it,y;
		if(check(x,x)) {del(x,x); continue;}
		y=*next(it);
		if(check(x,y)) {del(x,y); continue;}
		del(x,(*prev(sb.end())).se);
	}
	for(pii te:rv) cout<<te.fi<<' '<<te.se<<'\n';
	return 0;
}