vj1445 &eacute;™&para;&eacute;™&para;&aelig;Š&cent;&egrave;‹&sup1;&aelig;žœ

# Vj1445 &eacute;™&para;&eacute;™&para;&aelig;Š&cent;&egrave;‹&sup1;&aelig;žœ

This preview shows pages 1–2. Sign up to view the full content.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: const maxn=100000; var n,m:longint; a,w,num:array[0..maxn] of longint; f:array[0..maxn] of int64; procedure init; var i:longint; begin readln(n,m); for i:=1 to n do read(a[i]); for i:=1 to m do read(w[i]); end; procedure qs_w(l,r:longint); var i,j,mid,t:longint; begin i:=l; j:=r; mid:=w[(i+j) >> 1]; repeat while w[i]>mid do inc(i); while w[j]<mid do dec(j); if i<=j then begin t:=w[i]; w[i]:=w[j]; w[j]:=t; t:=num[i]; num[i]:=num[j]; num[j]:=t; inc(i); dec(j); end; until i>j; if j>l then qs_w(l,j); if i<r then qs_w(i,r); end; procedure qs_a(l,r:longint); var i,j,mid,t:longint; begin i:=l; j:=r; mid:=a[(i+j) >> 1]; repeat while a[i]>mid do inc(i); while a[j]<mid do dec(j); if i<=j then begin t:=a[i]; a[i]:=a[j]; a[j]:=t; inc(i); dec(j); end; until i>j; if j>l then qs_a(l,j); if i<r then qs_a(i,r); end; procedure main; var i:longint; begin for i:=1 to m do num[i]:=i; qs_w(1,m); qs_a(1,n); for i:=1 to n do inc(f[num[(i-1) mod m+1]],a[i]); end; procedure print; var i:longint; begin for i:=1 to m-1 do write(f[i],' '); writeln(f[m]); end; begin init; main; print; end. ...
View Full Document

## This note was uploaded on 02/21/2011 for the course CS 001 taught by Professor 001 during the Spring '11 term at Shandong University.

### Page1 / 2

Vj1445 &eacute;™&para;&eacute;™&para;&aelig;Š&cent;&egrave;‹&sup1;&aelig;žœ

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online