- 9


return

 

3. ­

SN

= ((1) - s(l))×(m(l) - (1)) + ... + (c(N) - s(N))×(m(N) - p(N)).

­. S := 0 S0 = 0.

k- ­

 

Sk = Sk-1

+ (c(k)-

s(k))-(m(k) - p(k)) = ((1) - s(l))×(m(l) - p(l)) + ... + (c(k) - s(k))×(m(k) - p(k)).

 

. ,

SN

= ((1) - s(l))×(m(l) - (1)) + ... + (c(N) - s(N))×(m(N) - p(N)).

.

, , r1, r2, ..., rN ­ x[l:N].

­ L(1:N), , x(k) = p(L(k)) k = 1, ..., N.

 

sortdan: '

x[1:N] dim x(N)

'

k = 1 N for k = 1 to N

L(k) = k L(k) = k

x(k)=p(L(k)) x(k)=p(L(k))

next k

- gosub sortmas '