import sys input = sys.stdin.readline from operator import itemgetter import time from random import randint time0=time.time() N,Q,WT,ST=map(int,input().split()) W=list(map(int,input().split())) LR=[list(map(int,input().split()))+[i+1] for i in range(Q)] LR2=sorted(LR,key=itemgetter(0)) LIST=[[] for i in range(1000)] for x,y,ind in LR2: LIST[x//530].append((y,ind)) ANS=[] count=0 for i in range(1000): if LIST[i]==[]: continue if count%2==0: LIST[i].sort(key=itemgetter(0)) else: LIST[i].sort(key=itemgetter(0),reverse=True) for _,ind in LIST[i]: ANS.append(ind) count+=1 SUM=[0] for w in W: SUM.append(SUM[-1]+w) def score(x,y): if x==-1: a,b,_=LR[y-1] return SUM[b]-SUM[a-1] else: a,b,_=LR[y-1] c,d,_=LR[x-1] a2,b2=min(a,c),max(a,c) c2,d2=min(b,d),max(b,d) return SUM[b2-1]-SUM[a2-1]+SUM[d2]-SUM[c2] def score_reverse(x,y): sc=0 if x==0: a=ANS[x] b=ANS[y] c=ANS[y+1] sc-=score(-1,a)+score(a,b)+score(b,c) sc+=score(-1,b)+score(b,a)+score(a,c) return sc if y==len(ANS)-1: a=ANS[x-1] b=ANS[x] c=ANS[y] sc-=score(a,b)+score(b,c) sc+=score(a,c)+score(c,b) return sc a=ANS[x-1] b=ANS[x] c=ANS[y] d=ANS[y+1] sc-=score(a,b)+score(b,c)+score(c,d) sc+=score(a,c)+score(c,b)+score(b,d) return sc def last_score(ANS): sc=0 for i in range(len(ANS)): if i==0: sc+=score(-1,ANS[0]) else: sc+=score(ANS[i-1],ANS[i]) return sc while time.time()-time0<4.7: k=randint(0,len(ANS)-2) if score_reverse(k,k+1)<0: ANS[k],ANS[k+1]=ANS[k+1],ANS[k] print(*ANS)