During one swap a pair of people swaps cards (each person gives one card and takes one card ).The aim of allNPeople is as follows: each of them shoshould give out all the cards he had initially (that is, all cards of his color ). your task is to denote whether such sequence of swaps is possible. if the answer is positive, you should list all the swaps.
InputThe first line contains integersN(1? ≤?N? ≤? 200000) andS(1? ≤?S? ≤? (200000). The second line containsNNumbers,I-Th number stands for how many cardsI-Th player has by the moment the game starts. It is possible that a player has no cards initially.
OutputOn the first line print "No" if such sequence of swaps is impossible. Otherwise, print "Yes". If the answer is positive, next print numberK-The number of the swaps. Then onKLines describe the swaps by pairs of indices of the swapping players. Print the swaps and the numbers of the swaps in any order.
Sample test (s) input4 82 2 2 2
OutputYes44 34 21 31 2
Input6 121 1 2 2 3 3
OutputYes66 56 46 35 45 32 1
Input5 50 0 0 0 5
OutputNo
The question has three conditions.
1. Each person can only exchange their own colors.
2. Everyone cannot accept their own colors or their own colors, even if they do not have their own colors.
3. Each person swaps their cards each time they exchange
Priority queue + bfs is similar to a simulated process. Here, the make_pair () function is skillfully used, which is equivalent to a first second struct.
# Include
# Include
# Include
# Include
# Include
# Include
# Define N 222222 # define ll _ int64 # define INF 0x3f3f3fusing namespace std; typedef pair
Pp; pp ans [N]; int a, B; int x; int n, s; int main () {cin> n> s; priority_queue
Q; for (int I = 1; I <= n; I ++) {scanf ("% d", & x); q. push (make_pair (x, I) ;}// for (int I = 1; I <= n; I ++) // sort by first in ascending order, then sort by second from large to small // {// pp a; // a = q. top (); // q. pop (); // cout <