构造。从a[i]最小的开始放置,例如放置了a[p],那么还未放置的,还需要建边的那个点 需求量-1,然后把边连起来。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
inline int read()
{
char c = getchar(); while(!isdigit(c)) c = getchar(); int x = ;
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
return x;
} const int maxn=+;
int T,n,sz;
struct X{int f,num; }s[maxn],ans[maxn*maxn]; bool cmp(X a, X b) {return a.num<b.num; } int main()
{
scanf("%d",&T); int cas=;
while(T--)
{
scanf("%d",&n); sz=;
for(int i=;i<=n;i++) { scanf("%d",&s[i].num); s[i].f=i; }
sort(s+,s++n,cmp);
bool fail=;
for(int i=;i<=n;i++)
{
if(s[i].num!=) { fail=; break; }
for(int j=i+;j<=n;j++)
{
if(s[j].num==) continue;
ans[sz].f=s[i].f; ans[sz].num=s[j].f; sz++; s[j].num--;
}
} printf("Case #%d: ",cas++);
if(fail==) { printf("No\n"); continue; }
else printf("Yes\n");
printf("%d\n",sz);
for(int i=;i<sz;i++) printf("%d %d\n",ans[i].num,ans[i].f);
}
return ;
}