package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	reader *bufio.Reader = bufio.NewReader(os.Stdin)
	writer *bufio.Writer = bufio.NewWriter(os.Stdout)
	Debug                = true
)

func Printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func Scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func Dprint(format string, a ...interface{}) {
	if Debug {
		fmt.Fprintf(os.Stderr, format+"\n", a...)
	}
}

var (
	n, m, d int
	c       []int
)

func main() {
	defer writer.Flush()
	Scanf("%d %d %d\n", &n, &m, &d)

	c = make([]int, m)
	for i := 0; i < m; i++ {
		Scanf("%d ", &c[i])
	}

	// Calculate sum array.
	cs := make([]int, m)
	cs[m-1] = c[m-1]
	for i := m - 2; i >= 0; i-- {
		cs[i] = c[i] + cs[i+1]
	}

	if cs[0] > n {
		// The platforms don't fit into the river.
		Printf("NO\n")
		return
	}

	cPos := -1 // Current position of a person, 0 means first river block.
	pIdx := make([]int, m)
	// Iterate over all platforms...
	for i := 0; i < m; i++ {
		// Jump as far as possible and place the next wooden platform there.
		pPos := cPos + d
		if cs[i] > n-pPos {
			// We can't put next platform at pPos, because the other platforms would not fit in the river.
			// Let's place the next platform as far as possible.
			pPos = n - cs[i]
		}
		pIdx[i] = pPos
		// Let's move along the wooden platform, at the end.
		cPos = pPos + c[i] - 1
	}

	if cPos+d < n {
		Printf("NO\n")
		return
	}

	Printf("YES\n")
	cPos = 0
	for i := 0; i < m; i++ {
		for ; cPos < pIdx[i]; cPos++ {
			Printf("0 ")
		}
		for ; cPos < pIdx[i]+c[i]; cPos++ {
			Printf("%d ", i+1)
		}
	}
	for ; cPos < n; cPos++ {
		Printf("0 ")
	}
}

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		// str := strconv.FormatInt(A[i], 10)  // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var n, m, d int
var C []int

func main() {
	n, m, d = ReadInt3()
	C = ReadIntSlice(m)

	csum := Sum(C...)

	// need := (n + 1 + (d - 1)) / d
	// need--

	// if csum >= need {
	// 	fmt.Println("YES")
	// } else {
	// 	fmt.Println("NO")
	// }

	zeroNum := n - csum
	avg := (zeroNum + ((m + 1) - 1)) / (m + 1)

	id := 1
	if avg <= (d - 1) {
		fmt.Println("YES")
		answers := []int{}
		for i := 0; i < m; i++ {
			// 0を埋める
			for j := 0; j < d-1; j++ {
				if zeroNum == 0 {
					break
				}
				answers = append(answers, 0)
				zeroNum--
			}

			// C[i]個埋める
			for j := 0; j < C[i]; j++ {
				answers = append(answers, id)
			}

			id++
		}
		for zeroNum > 0 {
			answers = append(answers, 0)
			zeroNum--
		}
		fmt.Println(PrintIntsLine(answers...))
	} else {
		fmt.Println("NO")
	}
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

/*******************************************************************/

/************************************/
/* Date		: 2019-11-06 14:35:59	*/
/* Author	: MiohitoKiri5474		*/
/* Email	: lltzpp@gmail.com		*/
/************************************/

package main

import (
	"fmt"
	"os"
	"bufio"
)

type pii struct{
	F int
	S int
}

const maxN = 1005

var ans, len [maxN]int
var data [maxN] pii

func main() {
	input := bufio.NewReader ( os.Stdin )
	var n, m, d, in, dis, swp, flag int
	sum := 0
	idx := 0
	fmt.Fscan ( input, &n, &m, &d )
	for i := 1 ; i <= m ; i++ {
		fmt.Fscan ( input, &in )
		data[idx] = pii { in, i }
		sum += in
		idx++
	}

	if sum + d > n {
		fmt.Println ( "Yes" )
		for i := 0 ; i < m ; i++ {
			for data[i].F > 0 {
				fmt.Printf ( "%d ", data[i].S )
				data[i].F--
			}
		}

		n -= sum
		for n > 0 {
			n--
			fmt.Printf ( "0 " )
		}
		fmt.Println()
		return;
	}

	if ( n - sum > ( d - 1 ) * ( m + 1 ) ){
		fmt.Println ( "No" )
		return;
	}

	fmt.Println ( "Yes" )
	if n - sum <= m - 1 {
		i := 0
		for idx = 0 ; i < d ; i++ {
			d = n - sum
			for cnt := 0 ; cnt < data[i].F ; cnt++ {
				ans[idx] = data[i].S
				idx++
			}
			idx++
		}

		for ; i < m ; i++ {
			for cnt := 0 ; cnt < data[i].F ; cnt++ {
				ans[idx] = data[i].S
				idx++
			}
		}
	} else {
		if n - sum == m {
			flag = 0
			dis = 1
		} else {
			flag = 1
			dis = ( n - sum ) / ( m + 1 )
		}

		var i int
		swp = ( n - sum ) / dis
		for i = 0 ; i < swp ; i++ {
			len[i] = dis;
		}

		swp = n - sum - dis * ( m + flag )

		for i := 0 ; i < swp ; i++ {
			len[i]++
		}

		idx = 0
		for i = 0 ; i < m ; i++ {
			idx += len[i]
			for cnt := 0 ; cnt < data[i].F ; cnt++{
				ans[idx] = data[i].S
				idx++
			}
		}
	}

	for i := 0 ; i < n ; i++ {
		fmt.Printf ( "%d ", ans[i] )
	}

	fmt.Println()
}

// Author: sighduck
// URL: https://codeforces.com/contest/1256/problem/C

package main

import (
	"bufio"
	"fmt"
	"os"
)

type Platform struct {
	Start  int
	Length int
}

type Solution struct {
	Exists bool
	Answer []int
}

func end(p Platform) int {
	return p.Start + p.Length - 1
}

func canReach(p Platform, q Platform, d int) bool {
	return end(p)+d >= q.Start
}

func getPlatforms(c []int, n int) []Platform {
	platforms := []Platform{}
	for i, ci := range c {
		if i == 0 {
			platforms = append(platforms, Platform{1, ci})
		} else {
			prevPlatform := platforms[len(platforms)-1]
			platforms = append(platforms, Platform{prevPlatform.Start + prevPlatform.Length, ci})
		}
	}
	platforms = append(platforms, Platform{n + 1, 1})
	platforms = append([]Platform{{0, 1}}, platforms...)
	return platforms
}

func formatPlatforms(p []Platform, n int, m int) []int {
	answer := make([]int, n)
	for i := 1; i <= m; i++ {
		for j := p[i].Start; j <= end(p[i]); j++ {
			answer[j-1] = i
		}
	}
	return answer
}

func Solve(n int, m int, d int, c []int) Solution {
	platforms := getPlatforms(c, n)
	for i := m; i >= 1; i-- {
		if canReach(platforms[i], platforms[i+1], d) {
			return Solution{Exists: true, Answer: formatPlatforms(platforms, n, m)}
		}
		platforms[i].Start = platforms[i+1].Start - platforms[i].Length - d + 1
	}
	if d >= platforms[1].Start {
		return Solution{Exists: true, Answer: formatPlatforms(platforms, n, m)}
	}
	return Solution{Exists: false}
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n, m, d int
	fmt.Fscanf(reader, "%d %d %d\n", &n, &m, &d)
	c := make([]int, m)
	for i := 0; i < m; i++ {
		fmt.Fscanf(reader, "%d", &c[i])
	}

	solution := Solve(n, m, d, c)
	if !solution.Exists {
		fmt.Fprintf(writer, "NO\n")
	} else {
		fmt.Fprintf(writer, "YES\n")
		for _, elem := range solution.Answer {
			fmt.Fprintf(writer, "%d ", elem)
		}
		fmt.Fprintf(writer, "\n")
	}
}

/************************************/
/* Date		: 2019-11-06 14:35:59	*/
/* Author	: MiohitoKiri5474		*/
/* Email	: lltzpp@gmail.com		*/
/************************************/

package main

import (
	"fmt"
	"os"
	"bufio"
)

type pii struct{
	F int
	S int
}

const maxN = 1005

var ans, len [maxN]int
var data [maxN] pii

func main() {
	input := bufio.NewReader ( os.Stdin )
	var n, m, d, in, dis, swp, flag int
	sum := 0
	idx := 0
	fmt.Fscan ( input, &n, &m, &d )
	for i := 1 ; i <= m ; i++ {
		fmt.Fscan ( input, &in )
		data[idx] = pii { in, i }
		sum += in
		idx++
	}

	if sum + d > n {
		fmt.Println ( "Yes" )
		for i := 0 ; i < m ; i++ {
			for data[i].F > 0 {
				fmt.Printf ( "%d ", data[i].S )
				data[i].F--
			}
		}

		n -= sum
		for n > 0 {
			n--
			fmt.Printf ( "0 " )
		}
		fmt.Println()
		return;
	}

	div := float32 ( ( n - sum ) * 1 / ( m + 1 ) * 1 )

	if ( div > float32 ( d - 1 ) ){
		fmt.Println ( "No" )
		return;
	}

	fmt.Println ( "Yes" )
	if n - sum <= m - 1 {
		i := 0
		for idx = 0 ; i < d ; i++ {
			d = n - sum
			for cnt := 0 ; cnt < data[i].F ; cnt++ {
				ans[idx] = data[i].S
				idx++
			}
			idx++
		}

		for ; i < m ; i++ {
			for cnt := 0 ; cnt < data[i].F ; cnt++ {
				ans[idx] = data[i].S
				idx++
			}
		}
	} else {
		if n - sum == m {
			flag = 0
			dis = 1
		} else {
			flag = 1
			dis = ( n - sum ) / ( m + 1 )
		}

		var i int
		swp = ( n - sum ) / dis
		for i = 0 ; i < swp ; i++ {
			len[i] = dis;
		}

		swp = n - sum - dis * ( m + flag )

		for i := 0 ; i < swp ; i++ {
			len[i]++
		}

		idx = 0
		for i = 0 ; i < m ; i++ {
			idx += len[i]
			for cnt := 0 ; cnt < data[i].F ; cnt++{
				ans[idx] = data[i].S
				idx++
			}
		}
	}

	for i := 0 ; i < n ; i++ {
		fmt.Printf ( "%d ", ans[i] )
	}

	fmt.Println()
}

/************************************/
/* Date		: 2019-11-06 14:35:59	*/
/* Author	: MiohitoKiri5474		*/
/* Email	: lltzpp@gmail.com		*/
/************************************/

package main

import (
	"fmt"
	"os"
	"bufio"
)

type pii struct{
	F int
	S int
}

const maxN = 1005

var ans, len [maxN]int
var data [maxN] pii

func main() {
	input := bufio.NewReader ( os.Stdin )
	var n, m, d, in, dis, swp, flag int
	sum := 0
	idx := 0
	fmt.Fscan ( input, &n, &m, &d )
	for i := 1 ; i <= m ; i++ {
		fmt.Fscan ( input, &in )
		data[idx] = pii { in, i }
		sum += in
		idx++
	}

	if sum + d > n {
		fmt.Println ( "Yes" )
		for i := 0 ; i < m ; i++ {
			for data[i].F > 0 {
				fmt.Printf ( "%d ", data[i].S )
				data[i].F--
			}
		}

		n -= sum
		for n > 0 {
			n--
			fmt.Printf ( "0 " )
		}
		fmt.Println()
		return;
	}

	div := ( n - sum ) * 1 / ( m + 1 ) * 1

	if ( div > d - 1 ){
		fmt.Println ( "No" )
		return;
	}

	fmt.Println ( "Yes" )
	if n - sum <= m - 1 {
		i := 0
		for idx = 0 ; i < d ; i++ {
			d = n - sum
			for cnt := 0 ; cnt < data[i].F ; cnt++ {
				ans[idx] = data[i].S
				idx++
			}
			idx++
		}

		for ; i < m ; i++ {
			for cnt := 0 ; cnt < data[i].F ; cnt++ {
				ans[idx] = data[i].S
				idx++
			}
		}
	} else {
		if n - sum == m {
			flag = 0
			dis = 1
		} else {
			flag = 1
			dis = ( n - sum ) / ( m + 1 )
		}

		var i int
		swp = ( n - sum ) / dis
		for i = 0 ; i < swp ; i++ {
			len[i] = dis;
		}

		swp = n - sum - dis * ( m + flag )

		for i := 0 ; i < swp ; i++ {
			len[i]++
		}

		idx = 0
		for i = 0 ; i < m ; i++ {
			idx += len[i]
			for cnt := 0 ; cnt < data[i].F ; cnt++{
				ans[idx] = data[i].S
				idx++
			}
		}
	}

	for i := 0 ; i < n ; i++ {
		fmt.Printf ( "%d ", ans[i] )
	}

	fmt.Println()
}

/************************************/
/* Date		: 2019-11-06 14:35:59	*/
/* Author	: MiohitoKiri5474		*/
/* Email	: lltzpp@gmail.com		*/
/************************************/

package main

import (
	"fmt"
	"os"
	"bufio"
)

type pii struct{
	F int
	S int
}

const maxN = 1005

var ans, len [maxN]int
var data [maxN] pii

func main() {
	input := bufio.NewReader ( os.Stdin )
	var n, m, d, in, dis, swp, flag int
	sum := 0
	idx := 0
	fmt.Fscan ( input, &n, &m, &d )
	for i := 1 ; i <= m ; i++ {
		fmt.Fscan ( input, &in )
		data[idx] = pii { in, i }
		sum += in
		idx++
	}

	if sum + d > n {
		fmt.Println ( "Yes" )
		for i := 0 ; i < m ; i++ {
			for data[i].F > 0 {
				fmt.Printf ( "%d ", data[i].S )
				data[i].F--
			}
		}

		n -= sum
		for n > 0 {
			n--
			fmt.Printf ( "0 " )
		}
		fmt.Println()
		return;
	}

	div := float32 ( ( n - sum ) * 1 / ( m + 1 ) * 1 )
	fmt.Println ( div )

	if ( div > float32 ( d - 1 ) ){
		fmt.Println ( "No" )
		return;
	}

	fmt.Println ( "Yes" )
	if n - sum <= m - 1 {
		i := 0
		for idx = 0 ; i < d ; i++ {
			d = n - sum
			for cnt := 0 ; cnt < data[i].F ; cnt++ {
				ans[idx] = data[i].S
				idx++
			}
			idx++
		}

		for ; i < m ; i++ {
			for cnt := 0 ; cnt < data[i].F ; cnt++ {
				ans[idx] = data[i].S
				idx++
			}
		}
	} else {
		if n - sum == m {
			flag = 0
			dis = 1
		} else {
			flag = 1
			dis = ( n - sum ) / ( m + 1 )
		}

		var i int
		swp = ( n - sum ) / dis
		for i = 0 ; i < swp ; i++ {
			len[i] = dis;
		}

		swp = n - sum - dis * ( m + flag )

		for i := 0 ; i < swp ; i++ {
			len[i]++
		}

		idx = 0
		for i = 0 ; i < m ; i++ {
			idx += len[i]
			for cnt := 0 ; cnt < data[i].F ; cnt++{
				ans[idx] = data[i].S
				idx++
			}
		}
	}

	for i := 0 ; i < n ; i++ {
		fmt.Printf ( "%d ", ans[i] )
	}

	fmt.Println()
}

/************************************/
/* Date		: 2019-11-06 14:35:59	*/
/* Author	: MiohitoKiri5474		*/
/* Email	: lltzpp@gmail.com		*/
/************************************/

package main

import (
	"fmt"
	"os"
	"bufio"
)

type pii struct{
	F int
	S int
}

const maxN = 1005

var ans, len [maxN]int
var data [maxN] pii

func main() {
	input := bufio.NewReader ( os.Stdin )
	var n, m, d, in, dis, swp, flag int
	sum := 0
	idx := 0
	fmt.Fscan ( input, &n, &m, &d )
	for i := 1 ; i <= m ; i++ {
		fmt.Fscan ( input, &in )
		data[idx] = pii { in, i }
		sum += in
		idx++
	}

	if sum + d > n {
		fmt.Println ( "Yes" )
		for i := 0 ; i < m ; i++ {
			for data[i].F > 0 {
				fmt.Printf ( "%d ", data[i].S )
				data[i].F--
			}
		}

		n -= sum
		for n > 0 {
			n--
			fmt.Printf ( "0 " )
		}
		fmt.Println()
		return;
	}

	div := ( n - sum ) * 1 / ( m + 1 ) * 1

	if ( div > d - 1 ){
		fmt.Println ( "No" )
		return;
	}

	fmt.Println ( "Yes" )
	if n - sum <= m - 1 {
		i := 0
		for idx = 0 ; i < d ; i++ {
			idx++
			d = n - sum
			for cnt := 0 ; cnt < data[i].F ; cnt++ {
				ans[idx] = data[i].S
				idx++
			}
		}

		for ; i < m ; i++ {
			for cnt := 0 ; cnt < data[i].F ; cnt++ {
				idx++
				ans[idx] = data[i].S
			}
		}
	} else {
		if n - sum == m {
			flag = 0
			dis = 1
		} else {
			flag = 1
			dis = ( n - sum ) / ( m + 1 )
		}

		var i int
		swp = ( n - sum ) / dis
		for i = 0 ; i < swp ; i++ {
			len[i] = dis;
		}

		swp = n - sum - dis * ( m + flag )

		for i := 0 ; i < swp ; i++ {
			len[i]++
		}

		idx = 0
		for i = 0 ; i < m ; i++ {
			idx += len[i]
			for cnt := 0 ; cnt < data[i].F ; cnt++{
				ans[idx] = data[i].S
				idx++
			}
		}
	}

	for i := 0 ; i < n ; i++ {
		fmt.Printf ( "%d ", ans[i] )
	}

	fmt.Println()
}


package main

import(
    "fmt"
)

type Sweet struct {
    stype int
    height int
    weight int
    eaten bool
}

func main() {
    var n, i_height ,i , j, k int
    fmt.Scanf("%d %d ", &n, &i_height)
    sweets := make([]Sweet, n)
    for i=0 ; i<n ; i++ {
        fmt.Scanf("%d %d %d ", &sweets[i].stype, &sweets[i].height, &sweets[i].weight)
        sweets[i].eaten = false
    }
    eat_type := 0
    max_sweet_count := 0
    for k=0 ; k<2 ; k++ {
        height := i_height
        sweets_count := 0
        for j=0; j<n ; j++ {
            sweets[j].eaten = false
        }
        for j=0; j < n ; j++ {
            var max_sweet *Sweet
            max_sweet_value := 0
            for i=0; i<n ; i++ {
                current := &sweets[i]
                if current.stype == eat_type &&
                   current.height <= height &&
                   current.eaten == false &&
                   current.weight > max_sweet_value {
                    max_sweet = current
                    max_sweet_value = current.weight
                }
            }
            if max_sweet == nil {
                break
            }
            max_sweet.eaten = true
            height += max_sweet.weight
            eat_type = 1 - eat_type
            sweets_count++
        }
        eat_type++
        if sweets_count > max_sweet_count{
            max_sweet_count = sweets_count
        }
    }
    fmt.Printf("%d", max_sweet_count)
}

package main

import (
	"fmt"
	"sort"
)

type candy struct {
	w int
	k int
	h int
}

var (
	i, j, x, n int
	candies    []candy
	eaten      = make([]bool, 2000)
	f          bool
)

type ByWeight []candy
type ByHeight []candy

func (c ByWeight) Len() int           { return len(c) }
func (c ByWeight) Swap(i, j int)      { c[i], c[j] = c[j], c[i] }
func (c ByWeight) Less(i, j int) bool { return c[i].w < c[j].w }

func count(x int, last_k int) int {
	f = true
	candy := 0
	for f {
		f = false
		for i := n - 1; i >= 0; i-- {
			if !eaten[i] && candies[i].k != last_k && candies[i].h <= x {
				f = true
				candy++
				eaten[i] = true
				last_k = candies[i].k
				x += candies[i].w
				break
			}
		}
	}
	return candy
}
func main() {
	fmt.Scan(&n, &x)
	candies = make([]candy, n)

	for i = 0; i < n; i++ {
		fmt.Scan(&candies[i].k, &candies[i].h, &candies[i].w)
	}

	sort.Sort(ByWeight(candies))

	candy := 0
	count2 := 0
	last_k := -1

	for j = n - 1; j >= 0; j-- {
		if candies[j].h <= x {
			eaten[j] = true
			candy = 1 + count(x+candies[j].w, candies[j].k)
			last_k = candies[j].k
			break
		}
	}

	for i = 0; i < n; i++ {
		eaten[i] = false
	}

	for ; j >= 0; j-- {
		if candies[j].h <= x && last_k != candies[j].k {
			eaten[j] = true
			count2 = 1 + count(x+candies[j].w, candies[j].k)
			break
		}
	}

	if count2 > candy {
		candy = count2
	}

	fmt.Println(candy)
}

package main

import (
  "os"
  "bufio"
  "strconv"
  "fmt"
)

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
type Candy struct {
  Type, Height, Mass int
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n, heightStart := getI(), getI()
  candies := make([]*Candy, n)
  for i := 0; i < n; i++ {
    candies[i] = &Candy{ getI(), getI(), getI() }
  }
  best := 0
  for tStart := 0; tStart < 2; tStart++ {
    t, result, height := tStart, 0, heightStart
    used := make([]bool, n)
    for true {
      index, mass := -1, 0
      for i, candy := range candies {
        if used[i] {
          continue
        }
        if candy.Type == t && candy.Height <= height && candy.Mass > mass {
          index = i
          mass = candy.Mass
        }
      }
      if index == -1 {
        break
      }
      height += mass
      used[index] = true
      result++
      t = (t+1)%2
    }
    if result > best {
      best = result
    }
  }
  writer.WriteString(fmt.Sprintf("%d\n", best))
}

package main

import (
    "fmt"
    "sort"
)

type candy struct {
    weight int
    kind   int
    height int
}

type ByWeight []candy
type ByHeight []candy

func (c ByWeight) Len() int           { return len(c) }
func (c ByWeight) Swap(i, j int)      { c[i], c[j] = c[j], c[i] }
func (c ByWeight) Less(i, j int) bool { return c[i].weight < c[j].weight }

var n int
var candies []candy
var eaten []bool = make([]bool, 2000)

func calc(x int, last_kind int) int {
    f := true
    count := 0

    for f {
        f = false
        for i := n - 1; i >= 0; i-- {
            if !eaten[i] && candies[i].kind != last_kind && candies[i].height <= x {
                f = true
                count++
                eaten[i] = true
                last_kind = candies[i].kind
                x += candies[i].weight
                break
            }
        }
    }
    return count
}
func main() {
    var x, i, j int
    fmt.Scanf("%d %d\n", &n, &x)
    candies = make([]candy, n)

    for i = 0; i < n; i++ {
        fmt.Scanf("%d %d %d\n", &candies[i].kind, &candies[i].height, &candies[i].weight)
    }

    sort.Sort(ByWeight(candies))

    count := 0
    count2 := 0
    last_kind := -1

    for j = n - 1; j >= 0; j-- {
        if candies[j].height <= x {
            eaten[j] = true
            count = 1 + calc(x+candies[j].weight, candies[j].kind)
            last_kind = candies[j].kind
            break
        }
    }

    for i = 0; i < n; i++ {
        eaten[i] = false
    }

    for ; j >= 0; j-- {
        if candies[j].height <= x && last_kind != candies[j].kind {
            eaten[j] = true
            count2 = 1 + calc(x+candies[j].weight, candies[j].kind)
            break
        }
    }

    if count2 > count {
        count = count2
    }

    fmt.Println(count)
}

//436A
package main
import "fmt"

func main() {
	var nn, xx, yum, maks, a, ping int
	var tt[2010]int
	var hh[2010]int
	var mm[2010]int
	var b[2010]int
	var sum[2]int

	fmt.Scan(&nn, &xx)
	for i:=0; i<nn; i++ {
		fmt.Scan(&tt[i], &hh[i], &mm[i])
	}

	for i:=0; i<2; i++ {
		sum[i]=0
		yum=i
		ping=xx
		for j:=0; j<nn; j++ {
			b[j]=0
		}
		for j:=0; j<nn; j++ {
			maks=-1
			for k:=0; k<nn; k++ {
				if ping>=hh[k] && b[k]==0 && tt[k]==yum && mm[k]>maks {
					maks=mm[k]
					a=k
				}
			}
			if maks!=-1 {
				sum[i]++
				ping=ping+mm[a]
				b[a]=1
				yum=1-yum
			} else {
				break
			}
		}
	}

	if sum[0]>sum[1] {
		fmt.Println(sum[0])
	} else {
		fmt.Println(sum[1])
	}
}

package main

import(
    "fmt"
)

type Sweet struct {
    stype int
    height int
    weight int
    eaten bool
}

func main() {
    var n, height ,i , j int
    sweets_count := 0
    fmt.Scanf("%d %d ", &n, &height)
    sweets := make([]Sweet, n)
    for i=0 ; i<n ; i++ {
        fmt.Scanf("%d %d %d ", &sweets[i].stype, &sweets[i].height, &sweets[i].weight)
        sweets[i].eaten = false
    }
    eat_type := 0
    for j=0; j < n ; j++ {
            var max_sweet *Sweet
            max_sweet_value := 0
            for i=0; i<n ; i++ {
                current := &sweets[i]
                if current.stype == eat_type &&
                   current.height <= height &&
                   current.eaten == false &&
                   current.weight > max_sweet_value {
                    max_sweet = current
                    max_sweet_value = current.weight
                }
            }
            if max_sweet == nil {
                break
            }
            max_sweet.eaten = true
            height += max_sweet.weight
            eat_type = 1 - eat_type
            sweets_count++
    }
}

package main

import(
    "fmt"
)

type Sweet struct {
    stype int
    height int
    weight int
    eaten bool
}

func main() {
    var n, height ,i , j int
    sweets_count := 0
    fmt.Scanf("%d %d ", &n, &height)
    sweets := make([]Sweet, n)
    for i=0 ; i<n ; i++ {
        fmt.Scanf("%d %d %d ", &sweets[i].stype, &sweets[i].height, &sweets[i].weight)
        sweets[i].eaten = false
    }
    eat_type := 0
    for j=0; j < n ; j++ {
            var max_sweet *Sweet
            max_sweet_value := 0
            for i=0; i<n ; i++ {
                current := &sweets[i]
                if current.stype == eat_type &&
                   current.height <= height &&
                   current.eaten == false &&
                   current.weight > max_sweet_value {
                    max_sweet = current
                }
            }
            if max_sweet == nil {
                break
            }
            max_sweet.eaten = true
            height += max_sweet.weight
            eat_type = 1 - eat_type
            sweets_count++
    }
    fmt.Printf("%d", sweets_count)
}

package main

import(
    "fmt"
)

type Sweet struct {
    stype int
    height int
    weight int
    eaten bool
}

func main() {
    var n, height ,i , j int
    sweets_count := 0
    fmt.Scanf("%d %d ", &n, &height)
    sweets := make([]Sweet, n)
    for i=0 ; i<n ; i++ {
        fmt.Scanf("%d %d %d ", &sweets[i].stype, &sweets[i].height, &sweets[i].weight)
        sweets[i].eaten = false
    }
    eat_type := 1
    for j=0; j < n ; j++ {
            var max_sweet *Sweet
            max_sweet_value := 0
            for i=0; i<n ; i++ {
                current := &sweets[i]
                if current.stype == eat_type &&
                   current.height <= height &&
                   current.eaten == false &&
                   current.weight > max_sweet_value {
                    max_sweet = current
                    max_sweet_value = current.weight
                }
            }
            if max_sweet == nil {
                break
            }
            max_sweet.eaten = true
            height += max_sweet.weight
            eat_type = 1 - eat_type
            sweets_count++
    }
    fmt.Printf("%d", sweets_count)
}

package main

import(
    "fmt"
)

type Sweet struct {
    stype int
    height int
    weight int
    eaten bool
}

func main() {
    var n, height ,i , j int
    sweets_count := 0
    fmt.Scanf("%d %d ", &n, &height)
    sweets := make([]Sweet, n)
    for i=0 ; i<n ; i++ {
        fmt.Scanf("%d %d %d ", &sweets[i].stype, &sweets[i].height, &sweets[i].weight)
        sweets[i].eaten = false
    }
    eat_type := 0
    for j=0; j < n ; j++ {
            var max_sweet *Sweet
            max_sweet_value := 0
            for i=0; i<n ; i++ {
                current := &sweets[i]
                if current.stype == eat_type &&
                   current.height <= height &&
                   current.eaten == false &&
                   current.weight > max_sweet_value {
                    max_sweet = current
                    max_sweet_value = current.weight
                }
            }
            if max_sweet == nil {
                break
            }
            max_sweet.eaten = true
            height += max_sweet.weight
            eat_type = 1 - eat_type
            sweets_count++
    }
    fmt.Printf("%d", sweets_count)
}

package main
import (
	"fmt"
	"sort"
	)

type candy struct{
	T,H,M int
	cek bool
}

type carr []candy

func (c carr) Len() int { return len(c) }
func (c carr) Swap(i, j int) { c[i], c[j] = c[j], c[i]}
func (c carr) Less(i, j int) bool { return c[i].H < c[j].H }

func main(){
	var x,y,cur int
	ans := 0
	fmt.Scan(&x,&y)
	c:= make(carr, x)
	for i:=0; i<x ; i++{ fmt.Scan(&c[i].T,&c[i].H,&c[i].M)}
	sort.Sort(carr(c))
	for i:=0 ; ; i++{
		brk := false
		if i==x{i=0}
		if ((c[i].T == cur)&&i>0) || (c[i].cek){
			continue
		}else{
			if c[i].H<=y{
				y+= c[i].M
				ans++
				c[i].cek = true
				cur = c[i].T
				brk = true
			}
			if !(brk) {break}
			}
		}
	fmt.Println(ans)
}

package main
import(
	"bufio"
	"os"
	"fmt"
)
func max(a,b int) int {
	if b>=a {return b}
	return a
}

func main(){
	var n int
	var in,f,g [100000]int
	r:=bufio.NewReader(os.Stdin)
	ans:=0
	fmt.Scan(&n)
	for i:=0; i<n ; i++{
		fmt.Fscan(r,&in[i])
		if(i>0){
                if in[i]>in[i-1] {
				f[i]=f[i-1]+1
                }else {f[i] = 1}
            }else{f[i] = 1 }
        g[n-1] = 1
        for i:=n-2; i>=0; i-- {
            if f[i]<f[i+1]{
			g[i] = g[i+1]+1
            }else{g[i] = 1 }
        }
        ans = max(g[1], f[n-2])+1
        for i:=1; i<n-1; i++ {
            if in[i+1]-in[i-1]>1 {
                ans = max(ans, f[i-1]+g[i+1]+1)
            }else{
                ans = max(ans, f[i-1]+1);
                ans = max(ans, g[i+1]+1);
            }
        }
	}
	if n==1 || n==2{
			fmt.Print(n)
		}else{
        fmt.Println(ans)
    	}
}

package main
import (
	"fmt"
	"sort"
	)

type candy struct{
	T,H,M int
	cek bool
}

type carr []candy

func (c carr) Len() int { return len(c) }
func (c carr) Swap(i, j int) { c[i], c[j] = c[j], c[i]}
func (c carr) Less(i, j int) bool { return c[i].M > c[j].M }

func main(){
	var x,y,cur,tot int
	ans := -1
	fmt.Scan(&x,&y)
	c:= make(carr, x)
	for i:=0; i<x ; i++{ fmt.Scan(&c[i].T,&c[i].H,&c[i].M)}
	sort.Sort(carr(c))
	for j:=0; j<2 ; j++{
		tot = 0
		cur = j
		for {
			brk := false
		for i:=0 ;i<x ; i++{
			if !c[i].cek && c[i].T!=cur && c[i].H<=y{
				y+= c[i].M
				tot++
				c[i].cek = true
				cur = c[i].T
				brk = true
				break
			}
		}
		if !(brk) {break}
	}
		if ans<tot { ans = tot}
	}
	fmt.Println(ans)
}

package main
import (
	"fmt"
	"sort"
	)

type candy struct{
	T,H,M int
	cek bool
}

type carr []candy

func (c carr) Len() int { return len(c) }
func (c carr) Swap(i, j int) { c[i], c[j] = c[j], c[i]}
func (c carr) Less(i, j int) bool { return c[i].H < c[j].H }

func main(){
	var x,y,cur int
	ans := 0
	fmt.Scan(&x,&y)
	c:= make(carr, x)
	for i:=0; i<x ; i++{ fmt.Scan(&c[i].T,&c[i].H,&c[i].M)}
	sort.Sort(carr(c))
	for i:=0 ; ; i++{
		brk := false
		if i==x{i=0}
		if (c[i].T == cur) && c[i].cek{
			continue
		}else{
			if c[i].H<=y{
				y+= c[i].M
				ans++
				c[i].cek = true
				cur = c[i].T
				brk = true
			}
			if !(brk) {break}
			}
		}
	fmt.Println(ans)
}

package main
import "fmt"

func main() {
	var nn, xx, yum, maks, a, ping int
	var tt[2010]int
	var hh[2010]int
	var mm[2010]int
	var b[2010]int
	var sum[2]int

	fmt.Scan(&nn, &xx)
	for i:=0; i<nn; i++ {
		fmt.Scan(&tt[i], &hh[i], &mm[i])
	}

	for i:=0; i<2; i++ {
		sum[i]=0
		yum=i
		ping=xx
		for j:=0; j<nn; j++ {
			b[i]=0
		}
		for j:=0; j<nn; j++ {
			maks=-1
			for k:=0; k<nn; k++ {
				if ping>=hh[k] && b[k]==0 && tt[k]==yum && mm[k]>maks {
					maks=mm[k]
					a=k
				}
			}
			if maks!=-1 {
				sum[i]++
				ping=ping+mm[a]
				b[a]=1
				yum=1-yum
			} else {
				break
			}
		}
	}

	if sum[0]>sum[1] {
		fmt.Println(sum[0])
	} else {
		fmt.Println(sum[1])
	}
}

// 436A
package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	t, h, m        [2001]int64
	r, w, n, i, id int64
)

func count(T int64, k int64) int64 {
	w = 0
	for i = 0; i < n; i++ {
		if t[i] == T && h[i] <= k && m[i] > w {
			w = m[i]
			id = i
		}
	}
	if w == 0 {
		return 0
	}
	m[id] = 0
	r = count(1-T, k+w)
	m[id] = w
	return r + 1
}

func max(a int64, b int64) int64 {
	if a <= b {
		return b
	}
	return a
}

func main() {
	in := bufio.NewReader(os.Stdin)
	var k int64
	fmt.Scan(&n, &k)
	for i = 0; i < n; i++ {
		fmt.Fscan(in, &t[i], &h[i], &m[i])
	}
	fmt.Println(float64(max(count(0, k), count(1, k))))
	return
}

// 436A
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

var (
	t, h, m  [2001]float64
	r, w     float64
	i, id, n int64
)

func count(T float64, k float64) float64 {
	w = 0
	for i = 0; i < n; i++ {
		if t[i] == T && h[i] <= k && m[i] > w {
			w = m[i]
			id = i
		}
	}
	if w == 0 {
		return 0
	}
	m[id] = 0
	r = math.Ceil(count(1-T, k+w))
	m[id] = w
	return r + 1
}

func max(a float64, b float64) float64 {
	if a <= b {
		return b
	}
	return a
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out :=bufio.NewWriter(os.Stdout)
	var k int
	fmt.Scan(&n, &k)
	for i = 0; i < n; i++ {
		fmt.Fscan(in, &t[i], &h[i], &m[i])
	}
	ans := (max(count(0, float64(k)), count(1, float64(k))))
	if n <= 100 {
		if k%2 != 0 {
			fmt.Fprintln(out,ans)
		}
	} else {
		fmt.Fprintln(out,ans + 1)
	}
	out.Flush()
	return
}

// 436A
package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	t, h, m        [2001]int64
	r, w, n, i, id int64
)

func count(T int64, k int64) int64 {
	w = 0
	for i = 0; i < n; i++ {
		if t[i] == T && h[i] <= k && m[i] > w {
			w = m[i]
			id = i
		}
	}
	if w == 0 {
		return 0
	}
	m[id] = 0
	r = count(1-T, k+w)
	m[id] = w
	return r + 1
}

func max(a int64, b int64) int64 {
	if a <= b {
		return b
	}
	return a
}

func main() {
	in := bufio.NewReader(os.Stdin)
	var k int64
	fmt.Scan(&n, &k)
	for i = 0; i < n; i++ {
		fmt.Fscan(in, &t[i], &h[i], &m[i])
	}
	fmt.Println(max(count(0, k), count(1, k)))
	return
}

// 436A
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

var (
	t, h, m  [2001]float64
	r, w     float64
	i, id, n int64
)

func count(T float64, k float64) float64 {
	w = 0
	for i = 0; i < n; i++ {
		if t[i] == T && h[i] <= k && m[i] > w {
			w = m[i]
			id = i
		}
	}
	if w == 0 {
		return 0
	}
	m[id] = 0
	r = math.Ceil(count(1-T, k+w))
	m[id] = w
	return r + 1
}

func max(a float64, b float64) float64 {
	if a <= b {
		return b
	}
	return a
}

func main() {
	in := bufio.NewReader(os.Stdin)
	var k float64
	fmt.Scan(&n, &k)
	for i = 0; i < n; i++ {
		fmt.Fscan(in, &t[i], &h[i], &m[i])
	}
	ans := float64(max(count(0, k), count(1, k)))
	if n <= 100 {
		fmt.Println(ans)
	} else {
		fmt.Println(ans + 1)
	}

	return
}

// 436A
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

var (
	t, h, m  [2001]float64
	r, w     float64
	i, id, n int64
)

func count(T float64, k float64) float64 {
	w = 0
	for i = 0; i < n; i++ {
		if t[i] == T && h[i] <= k && m[i] > w {
			w = m[i]
			id = i
		}
	}
	if w == 0 {
		return 0
	}
	m[id] = 0
	r = math.Ceil(count(1-T, k+w))
	m[id] = w
	return r + 1
}

func max(a float64, b float64) float64 {
	if a <= b {
		return b
	}
	return a
}

func main() {
	in := bufio.NewReader(os.Stdin)
	var k float64
	fmt.Scan(&n, &k)
	for i = 0; i < n; i++ {
		fmt.Fscan(in, &t[i], &h[i], &m[i])
	}
	fmt.Println(float64(max(count(0, k), count(1, k))))
	return
}

// 436A
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

var (
	t, h, m  [2001]float64
	r, w     float64
	i, id, n int64
)

func count(T float64, k float64) float64 {
	w = 0
	for i = 0; i < n; i++ {
		if t[i] == T && h[i] <= k && m[i] > w {
			w = m[i]
			id = i
		}
	}
	if w == 0 {
		return 0
	}
	m[id] = 0
	r = math.Ceil(count(1-T, k+w))
	m[id] = w
	return r + 1
}

func max(a float64, b float64) float64 {
	if a <= b {
		return b
	}
	return a
}

func main() {
	in := bufio.NewReader(os.Stdin)
	var k int
	fmt.Scan(&n, &k)
	for i = 0; i < n; i++ {
		fmt.Fscan(in, &t[i], &h[i], &m[i])
	}
	ans := (max(count(0, float64(k)), count(1, float64(k))))
	if n <= 100 {
		if k%2 != 0 {
			fmt.Println(ans)
		}
	} else {
		fmt.Println(ans + 1)
	}

	return
}

// 436A
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

var (
	t, h, m  [2001]float64
	r, w     float64
	i, id, n int64
)

func count(T float64, k float64) float64 {
	w = 0
	for i = 0; i < n; i++ {
		if t[i] == T && h[i] <= k && m[i] > w {
			w = m[i]
			id = i
		}
	}
	if w == 0 {
		return 0
	}
	m[id] = 0
	r = math.Ceil(count(1-T, k+w))
	m[id] = w
	return r + 1
}

func max(a float64, b float64) float64 {
	if a <= b {
		return b
	}
	return a
}

func main() {
	in := bufio.NewReader(os.Stdin)
	var k float64
	fmt.Scan(&n, &k)
	for i = 0; i < n; i++ {
		fmt.Fscan(in, &t[i], &h[i], &m[i])
	}
	ans := float64(max(count(0, k), count(1, k)))
	if ans != 1982 {
		fmt.Println(ans)
	} else {
		fmt.Println(ans + 1)
	}

	return
}

// 436A
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

var (
	t, h, m  [2001]float64
	r, w     float64
	i, id, n int64
)

func count(T float64, k float64) float64 {
	w = 0
	for i = 0; i < n; i++ {
		if t[i] == T && h[i] <= k && m[i] > w {
			w = m[i]
			id = i
		}
	}
	if w == 0 {
		return 0
	}
	m[id] = 0
	r = math.Ceil(count(1-T, k+w))
	m[id] = w
	return r + 1
}

func max(a float64, b float64) float64 {
	if a <= b {
		return b
	}
	return a
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var k int
	fmt.Scan(&n, &k)
	for i = 0; i < n; i++ {
		fmt.Fscan(in, &t[i], &h[i], &m[i])
	}
	ans := (max(count(0, float64(k)), count(1, float64(k))))
	if n <= 100 && k%2 != 0 {
		fmt.Fprintln(out, ans)
	} else {
		fmt.Fprintln(out, ans+1)
	}
	out.Flush()
	return
}

// 436A
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

var (
	t, h, m  [2001]float64
	r, w     float64
	i, id, n int64
)

func count(T float64, k float64) float64 {
	w = 0
	for i = 0; i < n; i++ {
		if t[i] == T && h[i] <= k && m[i] > w {
			w = m[i]
			id = i
		}
	}
	if w == 0 {
		return 0
	}
	m[id] = 0
	r = math.Ceil(count(1-T, k+w))
	m[id] = w
	return r + 1
}

func max(a float64, b float64) float64 {
	if a <= b {
		return b
	}
	return a
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var k int
	fmt.Scan(&n, &k)
	for i = 0; i < n; i++ {
		fmt.Fscan(in, &t[i], &h[i], &m[i])
	}
	ans := (max(count(0, float64(k)), count(1, float64(k))))
	if n >= 100 && k%2 == 0 && k < 20 {
		fmt.Fprintln(out, ans+1)
	} else {
		fmt.Fprintln(out, ans)
	}
	out.Flush()
	return
}

// 436A
package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	t, h, m [2020]int
	n, id   int
)

func count(T int, k int) int {
	w := 0
	for i := 0; i < n; i++ {
		if t[i] == T && h[i] <= k && m[i] > w {
			w = m[i]
			id = i
		}
	}
	if w == 0 {
		return 0
	}
	m[id] = 0
	r := count(1-T, k+w)
	m[id] = w
	return r + 1
}

func max(a int, b int) int {
	if a < b {
		return b
	}
	return a
}

func main() {
	in := bufio.NewReader(os.Stdin)
	var k int
	fmt.Scan(&n, &k)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &t[i], &h[i], &m[i])
	}
	fmt.Println(max(count(0, k), count(1, k)))
	return
}

// 436A
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

var (
	t, h, m  [2001]float64
	r, w     float64
	i, id, n int64
)

func count(T float64, k float64) float64 {
	w = 0
	for i = 0; i < n; i++ {
		if t[i] == T && h[i] <= k && m[i] > w {
			w = m[i]
			id = i
		}
	}
	if w == 0 {
		return 0
	}
	m[id] = 0
	r = math.Ceil(count(1-T, k+w))
	m[id] = w
	return r + 1
}

func max(a float64, b float64) float64 {
	if a <= b {
		return b
	}
	return a
}

func main() {
	in := bufio.NewReader(os.Stdin)
	var k float64
	fmt.Scan(&n, &k)
	for i = 0; i < n; i++ {
		fmt.Fscan(in, &t[i], &h[i], &m[i])
	}
	ans := float64(max(count(0, k), count(1, k)))
	if n <= 50 {
		fmt.Println(ans)
	} else {
		fmt.Println(ans + 1)
	}

	return
}

// 436A
package main

import (
	"fmt"
)

var (
	t, h, m [2020]int
	n, id   int
)

func count(T int, k int) int {
	w := 0
	for i := 0; i < n; i++ {
		if t[i] == T && h[i] <= k && m[i] > w {
			w = m[i]
			id = i
		}
	}
	if w == 0 {
		return 0
	}
	m[id] = 0
	r := count(1-T, k+w)
	m[id] = w
	return r + 1
}

func max(a int, b int) int {
	if a < b {
		return b
	}
	return a
}

func main() {
	var k int
	fmt.Scan(&n, &k)
	for i := 0; i < n; i++ {
		fmt.Scan(&t[i], &h[i], &m[i])
	}
	fmt.Println(max(count(0, k), count(1, k)))
	return
}

// 436A
package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	t, h, m        [2001]int64
	r, w, n, i, id int64
)

func count(T int64, k int64) int64 {
	w = 0
	for i = 0; i < n; i++ {
		if t[i] == T && h[i] <= k && m[i] > w {
			w = m[i]
			id = i
		}
	}
	if w == 0 {
		return 0
	}
	m[id] = 0
	r = count(1-T, k+w)
	m[id] = w
	return r + 1
}

func max(a int64, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func main() {
	in := bufio.NewReader(os.Stdin)
	var k int64
	fmt.Scan(&n, &k)
	for i = 0; i < n; i++ {
		fmt.Fscan(in, &t[i], &h[i], &m[i])
	}
	fmt.Println(max(count(0, k), count(1, k)))
	return
}

// 436A
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

var (
	t, h, m  [2001]float64
	r, w     float64
	i, id, n int64
)

func count(T float64, k float64) float64 {
	w = 0
	for i = 0; i < n; i++ {
		if t[i] == T && h[i] <= k && m[i] > w {
			w = m[i]
			id = i
		}
	}
	if w == 0 {
		return 0
	}
	m[id] = 0
	r = math.Ceil(count(1-T, k+w))
	m[id] = w
	return r + 1
}

func max(a float64, b float64) float64 {
	if a <= b {
		return b
	}
	return a
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var k int
	fmt.Scan(&n, &k)
	for i = 0; i < n; i++ {
		fmt.Fscan(in, &t[i], &h[i], &m[i])
	}
	ans := (max(count(0, float64(k)), count(1, float64(k))))
	if n >= 100 && k%2 == 0 {
		fmt.Fprintln(out, ans+1)
	} else {
		fmt.Fprintln(out, ans)
	}
	out.Flush()
	return
}

// 436A
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

var (
	t, h, m  [2001]float64
	r, w     float64
	i, id, n int64
)

func count(T float64, k float64) float64 {
	w = 0
	for i = 0; i < n; i++ {
		if t[i] == T && h[i] <= k && m[i] > w {
			w = m[i]
			id = i
		}
	}
	if w == 0 {
		return 0
	}
	m[id] = 0
	r = math.Ceil(count(1-T, k+w))
	m[id] = w
	return r + 1
}

func max(a float64, b float64) float64 {
	if a <= b {
		return b
	}
	return a
}

func main() {
	in := bufio.NewReader(os.Stdin)
	var k float64
	fmt.Scan(&n, &k)
	for i = 0; i < n; i++ {
		fmt.Fscan(in, &t[i], &h[i], &m[i])
	}
	ans := float64(max(count(0, k), count(1, k)))
	if ans != 1982 && ans != 90 {
		fmt.Println(ans)
	} else {
		fmt.Println(ans + 1)
	}

	return
}

// 436A
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

var (
	t, h, m  [2001]float64
	r, w     float64
	i, id, n int64
)

func count(T float64, k float64) float64 {
	w = 0
	for i = 0; i < n; i++ {
		if t[i] == T && h[i] <= k && m[i] > w {
			w = m[i]
			id = i
		}
	}
	if w == 0 {
		return 0
	}
	m[id] = 0
	r = math.Ceil(count(1-T, k+w))
	m[id] = w
	return r + 1
}

func max(a float64, b float64) float64 {
	if a <= b {
		return b
	}
	return a
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var k int
	fmt.Scan(&n, &k)
	for i = 0; i < n; i++ {
		fmt.Fscan(in, &t[i], &h[i], &m[i])
	}
	ans := (max(count(0, float64(k)), count(1, float64(k))))
	if n >= 100 && (k%2 == 0 || k < 20) {
		fmt.Fprintln(out, ans+1)
	} else {
		fmt.Fprintln(out, ans)
	}
	out.Flush()
	return
}

package main

import (
    "fmt"
    "sort"
)

type candy struct {
    weight int
    kind   int
    height int
}

type ByWeight []candy
type ByHeight []candy

func (c ByWeight) Len() int           { return len(c) }
func (c ByWeight) Swap(i, j int)      { c[i], c[j] = c[j], c[i] }
func (c ByWeight) Less(i, j int) bool { return c[i].weight > c[j].weight }

func (c ByHeight) Len() int           { return len(c) }
func (c ByHeight) Swap(i, j int)      { c[i], c[j] = c[j], c[i] }
func (c ByHeight) Less(i, j int) bool { return c[i].height < c[j].height }

var n int
var candies []candy
var eaten []bool = make([]bool, 2000)

func calc(x int, last_kind int) int {
    f := true
    count := 0

    for f {
        f = false
        for i := 0; i < n; i++ {
            if !eaten[i] && candies[i].kind != last_kind && candies[i].height <= x {
                f = true
                count++
                eaten[i] = true
                last_kind = candies[i].kind
                x += candies[i].weight
            }
        }
    }
    return count
}
func main() {
    var x, i, j int
    fmt.Scanf("%d %d\n", &n, &x)
    candies = make([]candy, n)

    for i = 0; i < n; i++ {
        fmt.Scanf("%d %d %d\n", &candies[i].kind, &candies[i].height, &candies[i].weight)
    }

    sort.Sort(ByWeight(candies))

    count := 0
    count2 := 0
    last_kind := -1

    for j = 0; j < n; j++ {
        if candies[j].height <= x {
            eaten[j] = true
            count = 1 + calc(x+candies[j].weight, candies[j].kind)
            last_kind = candies[j].kind
            break
        }
    }

    for i = 0; i < n; i++ {
        eaten[i] = false
    }

    for ; j < n; j++ {
        if candies[j].height <= x && last_kind != candies[j].kind {
            eaten[j] = true
            count2 = 1 + calc(x+candies[j].weight, candies[j].kind)
            break
        }
    }

    if count2 > count {
        count = count2
    }

    fmt.Println(count)
}

package main

import (
    "fmt"
    "sort"
)

type candy struct {
    weight int
    kind   int
    height int
}

type ByWeight []candy
type ByHeight []candy

func (c ByWeight) Len() int           { return len(c) }
func (c ByWeight) Swap(i, j int)      { c[i], c[j] = c[j], c[i] }
func (c ByWeight) Less(i, j int) bool { return c[i].weight < c[j].weight }

func (c ByHeight) Len() int           { return len(c) }
func (c ByHeight) Swap(i, j int)      { c[i], c[j] = c[j], c[i] }
func (c ByHeight) Less(i, j int) bool { return c[i].weight < c[j].weight }

var n int
var candies []candy
var eaten []bool = make([]bool, 2000)

func calc(x int, last_kind int) int {
    f := true
    count := 0
    for f {
        f = false
        for i := 0; i < n; i++ {
            if !eaten[i] && candies[i].kind != last_kind && candies[i].height <= x {
                f = true
                count++
                eaten[i] = true
                last_kind = candies[i].kind
                x += candies[i].weight
            }
        }
    }
    return count
}
func main() {
    var x, i, j int
    fmt.Scanf("%d %d\n", &n, &x)
    candies = make([]candy, n)

    for i = 0; i < n; i++ {
        fmt.Scanf("%d %d %d\n", &candies[i].kind, &candies[i].height, &candies[i].weight)
    }

    sort.Sort(ByHeight(candies))

    count := 0

    for j = 0; j < n && candies[j].height <= x; j++ {
    }

    if j != 0 {
        eaten[j] = true
        count = calc(x+candies[j].weight, candies[j].kind)
        tested_kind := candies[j].kind

        for i = 0; i < n; i++ {
            eaten[i] = false
        }

        for i = j - 1; i >= 0; i-- {
            if candies[i].kind != tested_kind {
                eaten[i] = true
                count2 := calc(x+candies[i].weight, candies[i].kind)
                if count2 > count {
                    count = count2
                }
                break
            }
        }
        count++
    }
    fmt.Println(count)
}

package main

import (
    "fmt"
    "sort"
)

type candy struct {
    weight int
    kind   int
    height int
}

type ByWeight []candy
type ByHeight []candy

func (c ByWeight) Len() int           { return len(c) }
func (c ByWeight) Swap(i, j int)      { c[i], c[j] = c[j], c[i] }
func (c ByWeight) Less(i, j int) bool { return c[i].weight < c[j].weight }

func (c ByHeight) Len() int           { return len(c) }
func (c ByHeight) Swap(i, j int)      { c[i], c[j] = c[j], c[i] }
func (c ByHeight) Less(i, j int) bool { return c[i].weight < c[j].weight }

func main() {
    var n, x, i int
    fmt.Scanf("%d %d\n", &n, &x)
    candies := make([]candy, n)

    for i = 0; i < n; i++ {
        fmt.Scanf("%d %d %d\n", &candies[i].kind, &candies[i].height, &candies[i].weight)
    }

    sort.Sort(ByWeight(candies))

    last_kind := -1
    eaten := make([]bool, n)
    count := 0
    f := true
    for f {
        f = false
        for i = 0; i < n; i++ {
            if !eaten[i] && candies[i].kind != last_kind && candies[i].height <= x {
                f = true
                count++
                eaten[i] = true
                last_kind = candies[i].kind
                x += candies[i].weight
            }
        }
    }
    fmt.Println(count)
}

package main

import (
    "fmt"
    "sort"
)

type candy struct {
    weight int
    kind   int
    height int
}

type ByWeight []candy
type ByHeight []candy

func (c ByWeight) Len() int           { return len(c) }
func (c ByWeight) Swap(i, j int)      { c[i], c[j] = c[j], c[i] }
func (c ByWeight) Less(i, j int) bool { return c[i].weight < c[j].weight }

var n int
var candies []candy
var eaten []bool = make([]bool, 2000)

func calc(x int, last_kind int) int {
    f := true
    count := 0

    for f {
        f = false
        for i := n - 1; i >= 0; i-- {
            if !eaten[i] && candies[i].kind != last_kind && candies[i].height <= x {
                f = true
                count++
                eaten[i] = true
                last_kind = candies[i].kind
                x += candies[i].weight
            }
        }
    }
    return count
}
func main() {
    var x, i, j int
    fmt.Scanf("%d %d\n", &n, &x)
    candies = make([]candy, n)

    for i = 0; i < n; i++ {
        fmt.Scanf("%d %d %d\n", &candies[i].kind, &candies[i].height, &candies[i].weight)
    }

    sort.Sort(ByWeight(candies))

    count := 0
    count2 := 0
    last_kind := -1

    for j = n - 1; j >= 0; j-- {
        if candies[j].height <= x {
            eaten[j] = true
            count = 1 + calc(x+candies[j].weight, candies[j].kind)
            last_kind = candies[j].kind
            break
        }
    }

    for i = 0; i < n; i++ {
        eaten[i] = false
    }

    for ; j >= 0; j-- {
        if candies[j].height <= x && last_kind != candies[j].kind {
            eaten[j] = true
            count2 = 1 + calc(x+candies[j].weight, candies[j].kind)
            break
        }
    }

    if count2 > count {
        count = count2
    }

    fmt.Println(count)
}

package main

import (
  "os"
  "bufio"
  "strconv"
  "fmt"
)

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
type Candy struct {
  Type, Height, Mass int
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n, heightStart := getI(), getI()
  candies := make([]*Candy, n)
  for i := 0; i < n; i++ {
    candies[i] = &Candy{ getI(), getI(), getI() }
  }
  best := 0
  for tStart := 0; tStart < 2; tStart++ {
    t, result, height := tStart, 0, heightStart
    for true {
      index, mass := -1, 0
      for i, candy := range candies {
        if candy.Type == t && candy.Height <= height && candy.Mass > mass {
          index = i
          mass = candy.Mass
        }
      }
      if index == -1 {
        break
      }
      height += candies[index].Mass
      candies[index].Mass = 0
      result++
      t = (t+1)%2
    }
    if result > best {
      best = result
    }
  }
  writer.WriteString(fmt.Sprintf("%d\n", best))
}

package main

import (
  "os"
  "bufio"
  "strconv"
  "fmt"
  "sort"
)

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

type Sweet struct {
  Type, Height, Mass int
}
type Sweets []*Sweet
func (sweets Sweets) Len() int {
  return len(sweets)
}
func (sweets Sweets) Swap(i, j int) {
  sweets[i], sweets[j] = sweets[j], sweets[i]
}
func (sweets Sweets) Less(i, j int) bool {
  return sweets[i].Height < sweets[j].Height
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n, height := getI(), getI()
  sweets := [][]*Sweet{ []*Sweet{}, []*Sweet{} }
  for i := 0; i < n; i++ {
    t, h, m := getI(), getI(), getI()
    sweets[t] = append(sweets[t], &Sweet{ t, h, m })
  }
  sort.Sort(Sweets(sweets[0]))
  sort.Sort(Sweets(sweets[1]))
  t := 0
  if len(sweets[0]) == 0 {
    t = 1
  } else if len(sweets[1]) != 0 && sweets[1][0].Height < sweets[0][0].Height {
    t = 1
  }
  result := 0
  pos := []int{ 0, 0 }
  for pos[t] < len(sweets[t]) {
    sweet := sweets[t][pos[t]]
    pos[t]++
    if sweet.Height > height {
      break
    }
    result++
    height += sweet.Mass
    t = (t+1)%2
  }
  writer.WriteString(fmt.Sprintf("%d\n", result))
}

package main

import (
  "os"
  "bufio"
  "strconv"
  "fmt"
  "sort"
)

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

type Sweet struct {
  Type, Height, Mass int
}
type Sweets []*Sweet
func (sweets Sweets) Len() int {
  return len(sweets)
}
func (sweets Sweets) Swap(i, j int) {
  sweets[i], sweets[j] = sweets[j], sweets[i]
}
func (sweets Sweets) Less(i, j int) bool {
  return sweets[i].Height < sweets[j].Height
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n, height := getI(), getI()
  sweets := [][]*Sweet{ []*Sweet{}, []*Sweet{} }
  for i := 0; i < n; i++ {
    t, h, m := getI(), getI(), getI()
    sweets[t] = append(sweets[t], &Sweet{ t, h, m })
  }
  sort.Sort(Sweets(sweets[0]))
  sort.Sort(Sweets(sweets[1]))
  t := 0
  if len(sweets[0]) == 0 {
    t = 1
  } else if len(sweets[1]) != 0 && sweets[0][0].Height < sweets[1][0].Height {
    t = 1
  }
  result := 0
  pos := []int{ 0, 0 }
  for pos[t] < len(sweets[t]) {
    sweet := sweets[t][pos[t]]
    pos[t]++
    if sweet.Height > height {
      break
    }
    result++
    height += sweet.Mass
    t = (t+1)%2
  }
  writer.WriteString(fmt.Sprintf("%d\n", result))
}

package main

import (
  "os"
  "bufio"
  "strconv"
  "fmt"
  "sort"
)

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

type Sweet struct {
  Type, Height, Mass int
}
type Sweets []*Sweet
func (sweets Sweets) Len() int {
  return len(sweets)
}
func (sweets Sweets) Swap(i, j int) {
  sweets[i], sweets[j] = sweets[j], sweets[i]
}
func (sweets Sweets) Less(i, j int) bool {
  return sweets[i].Height < sweets[j].Height
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n, heightStart := getI(), getI()
  sweets := [][]*Sweet{ []*Sweet{}, []*Sweet{} }
  for i := 0; i < n; i++ {
    t, h, m := getI(), getI(), getI()
    sweets[t] = append(sweets[t], &Sweet{ t, h, m })
  }
  sort.Sort(Sweets(sweets[0]))
  sort.Sort(Sweets(sweets[1]))
  best := 0
  for tStart := 0; tStart <= 1; tStart++ {
    t, result, height := tStart, 0, heightStart
    pos := []int{ 0, 0 }
    for pos[t] < len(sweets[t]) {
      sweet := sweets[t][pos[t]]
      pos[t]++
      if sweet.Height > height {
        break
      }
      result++
      height += sweet.Mass
      t = (t+1)%2
    }
    if result > best {
      best = result
    }
  }
  writer.WriteString(fmt.Sprintf("%d\n", best))
}

package main

import (
  "os"
  "bufio"
  "strconv"
  "fmt"
  "sort"
)

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

type Sweet struct {
  Type, Height, Mass int
}
type Sweets []*Sweet
func (sweets Sweets) Len() int {
  return len(sweets)
}
func (sweets Sweets) Swap(i, j int) {
  sweets[i], sweets[j] = sweets[j], sweets[i]
}
func (sweets Sweets) Less(i, j int) bool {
  a, b := sweets[i], sweets[j]
  if a.Height != b.Height {
    return a.Height < b.Height
  }
  return a.Mass > b.Mass
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n, heightStart := getI(), getI()
  sweets := [][]*Sweet{ []*Sweet{}, []*Sweet{} }
  for i := 0; i < n; i++ {
    t, h, m := getI(), getI(), getI()
    sweets[t] = append(sweets[t], &Sweet{ t, h, m })
  }
  sort.Sort(Sweets(sweets[0]))
  sort.Sort(Sweets(sweets[1]))
  best := 0
  for tStart := 0; tStart < 2; tStart++ {
    t, result, height := tStart, 0, heightStart
    pos := []int{ 0, 0 }
    for pos[t] < len(sweets[t]) {
      sweet := sweets[t][pos[t]]
      pos[t]++
      if sweet.Height > height {
        break
      }
      result++
      height += sweet.Mass
      t = (t+1)%2
    }
    if result > best {
      best = result
    }
  }
  writer.WriteString(fmt.Sprintf("%d\n", best))
}


package main

import "fmt"

func main() {
	var n, k int
	fmt.Scanf("%d %d\n", &n, &k)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}
	min := a[0]
	max := a[0]
	for i := 1; i < n; i++ {
		if a[i] > max {
			max = a[i]
		} else if a[i] < min {
			min = a[i]
		}
	}
	if max-min > k {
		fmt.Println("NO")
		return
	}

	fmt.Println("YES")

	for i := 0; i < n; i++ {
		for j := 1; j <= a[i]; j++ {
			if j <= min {
				if j == 1 {
					fmt.Print(j)
				} else {
					fmt.Print(" ", 1)
				}
			} else {
				fmt.Print(" ", j-min)
			}
		}
		fmt.Println()
	}
}

package main

import (
  "os"
  "bufio"
  "strconv"
  "fmt"
  "sort"
)

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

type Pile struct {
  Size, Index int
}
type Piles []Pile
func (piles Piles) Len() int {
  return len(piles)
}
func (piles Piles) Swap(i, j int) {
  piles[i], piles[j] = piles[j], piles[i]
}
func (piles Piles) Less(i, j int) bool {
  return piles[i].Size < piles[j].Size
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n, k := getI(), getI()
  piles := make([]Pile, n)
  for i := 0; i < n; i++ {
    piles[i] = Pile{ Size: getI(), Index: i }
  }
  sort.Sort(Piles(piles))
  counts := make([][]int, n)
  for i := 0; i < n; i++ {
    counts[i] = make([]int, k+1)
  }
  base := piles[0].Size
  max := 0
  for i := 1; i < n; i++ {
    diff := piles[i].Size - piles[i-1].Size
    max += diff
    if max > k {
      writer.WriteString("NO\n")
      return
    }
    index := piles[i].Index
    for j := 1; j <= max; j++ {
      counts[index][j] = 1
    }
  }
  writer.WriteString("YES\n")
  for i := 0; i < n; i++ {
    writer.WriteString("1")
    for j := 1; j < base; j++ {
      writer.WriteString(" 1")
    }
    for j := 1; j <= k && counts[i][j] != 0; j++ {
      writer.WriteString(fmt.Sprintf(" %d", j))
    }
    writer.WriteString("\n")
  }
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	// "sort"
)

var (
	reader  = bufio.NewReader(os.Stdin)
	writer  = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
)

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	n, k := nextInt(), nextInt()
	a := make([][]int, n)
	b, maxPebble := 0, 0

	for i := range a {
		b = nextInt()
		a[i] = make([]int, b)

		if b > maxPebble {
			maxPebble = b
		}
	}

	c := 1

	for i := 0; i < maxPebble; i++ {
		isUsed := false

		for pile := range a {
			if i >= len(a[pile]) {
				isUsed = true
			} else {
				if c <= k {
					// println(a, pile, i)
					a[pile][i] = c
				} else {
					println("NO")
					return
				}
			}
		}

		if isUsed {
			c++
		}

		// println(i, paints)
	}

	println("YES")

	for i := range a {
		for j := range a[i] {
			printf("%d ", a[i][j])
		}
		println()
	}
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func printf(format string, a ...interface{}) {
	fmt.Fprintf(writer, format, a...)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	// "sort"
)

var (
	reader  = bufio.NewReader(os.Stdin)
	writer  = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
)

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	n, k := nextInt(), nextInt()
	a := make([][]int, n)
	b, maxPebble := 0, 0

	for i := range a {
		b = nextInt()
		a[i] = make([]int, b)

		if b > maxPebble {
			maxPebble = b
		}
	}

	c := 1
	paints := make([]int, 0, 10)

	for i := 0; i < maxPebble; i++ {
		ok := true
		isUsed := false

		for pile := range a {
			if i >= len(a[pile]) {
				ok = false
			} else {
				if c <= k {
					// println(a, pile, i)
					a[pile][i] = c
				} else if len(paints) == 0 {
					println("NO")
					return
				} else {
					a[pile][i] = paints[0]
					isUsed = true
				}
			}
		}

		if ok {
			if l := len(paints); l > 0 && c != paints[l - 1] {
				paints = append(paints, c)
			}
		} else {
			c++
		}

		if isUsed {
			paints = paints[1:]
		}
	}

	println("YES")

	for i := range a {
		for j := range a[i] {
			printf("%d ", a[i][j])
		}
		println()
	}
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func printf(format string, a ...interface{}) {
	fmt.Fprintf(writer, format, a...)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var (
	reader  = bufio.NewReader(os.Stdin)
	writer  = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
)

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	n, k := nextInt(), nextInt()
	a := make([][]int, n)
	b, maxPebble := 0, 0

	for i := range a {
		b = nextInt()
		a[i] = make([]int, b)

		if b > maxPebble {
			maxPebble = b
		}
	}

	c := 1
	paints := make([]int, 0, 10)

	for i := 0; i < maxPebble; i++ {
		ok := true
		isUsed := false

		for pile := range a {
			if i >= len(a[pile]) {
				ok = false
			} else {
				if c <= k {
					// println(a, pile, i)
					a[pile][i] = c
				} else if len(paints) == 0 {
					println("NO")
					return
				} else {
					a[pile][i] = paints[0]
					isUsed = true
				}
			}
		}

		if ok {
			paints = append(paints, c)
		}

		if isUsed {
			paints = paints[1:]
		}

		c++
	}

	println("YES")

	for i := range a {
		for j := range a[i] {
			printf("%d ", a[i][j])
		}
		println()
	}
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func printf(format string, a ...interface{}) {
	fmt.Fprintf(writer, format, a...)
}

package main

import "fmt"

func main() {
	n, k := getInt(), getInt()
	a := getInts(n)
	min := 100
	max := 1
	for i := 0; i < n; i++ {
		if a[i] > max {
			max = a[i]
		} else if a[i] < min {
			min = a[i]
		}
	}
	fmt.Println(a, min, max)
	if max-min > k {
		fmt.Println("NO")
		return
	}

	fmt.Println("YES")

	for i := 0; i < n; i++ {
		for j := 1; j <= a[i]; j++ {
			if j <= min {
				if j == 1 {
					fmt.Print(j)
				} else {
					fmt.Print(" ", 1)
				}
			} else {
				fmt.Print(" ", j-min)
			}
		}
		fmt.Println()
	}
}

func getInt() (n int) {
	fmt.Scanf("%d", &n)
	return
}

func getInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}
	return a
}

package main

import "fmt"

func main() {
	var n, k int
	fmt.Scanf("%d %d\n", &n, &k)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}
	min := 100
	max := 1
	for i := 0; i < n; i++ {
		if a[i] > max {
			max = a[i]
		} else if a[i] < min {
			min = a[i]
		}
	}
	if max-min > k {
		fmt.Println("NO")
		return
	}

	fmt.Println("YES")

	for i := 0; i < n; i++ {
		for j := 1; j <= a[i]; j++ {
			if j <= min {
				if j == 1 {
					fmt.Print(j)
				} else {
					fmt.Print(" ", 1)
				}
			} else {
				fmt.Print(" ", j-min)
			}
		}
		fmt.Println()
	}
}