Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:看不懂题目呀,哪位大哥帮帮忙!!

Posted by IceKingdom at 2008-10-31 16:56:05 on Problem 3273
In Reply To:Re:看不懂题目呀,哪位大哥帮帮忙!! Posted by:ecjtuQX at 2008-10-01 21:17:45
program         Montyly_Expense ;
const   maxn    = 110000 ;
var     a       : array[1..maxn] of longint ;
        n , m  , max , sum : longint ;

procedure       enter ;
var     i       : longint ;
begin
        readln( n , m ) ;
        max := -( maxlongint - 1 ) ;  sum := 0 ;
        for  i := 1 to n  do  begin
         readln( a[i] ) ;
         inc( sum , a[i] ) ;
         if  a[i] > max
          then  max := a[i] ;
        end ;
end ;

function        work( k : longint ) : longint ;
var     i , t : longint ;
begin
        work := 1 ;  t := 0 ;
        for  i := 1 to n  do
         if  t + a[i] <= k
          then  inc( t , a[i] )
          else  begin
           inc( work ) ;
           t := a[i] ;
          end ;
end ;

procedure       solve ;
var     k1 , k2 , k3 : longint ;
begin
        k1 := max ;  k2 := sum ;
        repeat
         k3 := ( k1 + k2 ) shr 1 ;
         if  work( k3 ) > m
          then  k1 := k3 + 1
          else  k2 := k3 ;
        until  k1 >= k2 ;
        writeln( k1 ) ;
end ;

begin
        assign( input , 't3273.in' ) ;  reset( input ) ;  assign( output , 't3273.out' ) ;  rewrite( output ) ;

         enter ;
         solve ;

        close( input ) ;  close( output ) ;
end .

110ms  二分晕呼呼的就过去了。。。

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator