• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            我希望你是我獨家記憶

            一段永遠封存的記憶,隨風而去
            posts - 263, comments - 31, trackbacks - 0, articles - 3
               :: 首頁 :: 新隨筆 ::  :: 聚合  :: 管理

            URAL1648

            Posted on 2008-10-31 22:53 Hero 閱讀(136) 評論(0)  編輯 收藏 引用 所屬分類: 代碼如詩--ACM
             1 // 1648 C++ Accepted 0.031 449 KB URAL
             2 
             3 #include <stdio.h>
             4 #include <stdlib.h>
             5 #include <string.h>
             6 
             7 //typedef long long llong ;
             8 typedef __int64 llong ;
             9 
            10 const int size = 20100 ;
            11 struct NODE {
            12     int num ;
            13     int posi ;
            14 };
            15 struct NODE node[size] ;
            16 struct NODE stack[size] ;
            17 int top ;
            18 
            19 int inn, ind ;
            20 llong sum, total ;
            21 llong mincost ;
            22 
            23 void input()
            24 {
            25     sum = 0 ;
            26     forint i=1; i<=inn; i++ )
            27     {
            28         scanf( "%d"&node[i].num ) ;
            29         sum += node[i].num ;
            30         node[i].num -= ind ;
            31         node[i].posi = i ;
            32     }
            33 }
            34 
            35 void process()
            36 {
            37     top = -1 ; mincost = 0 ;
            38     forint i=inn; i>=1; i-- )
            39     {
            40         if( node[i].num > 0 )
            41         {
            42             stack[++top].num = node[i].num ;
            43             stack[top].posi = node[i].posi ;
            44         }
            45         else if( node[i].num < 0 )
            46         {
            47             int temp = node[i].num ;
            48             while( top >= 0 && temp < 0 )
            49             {
            50                 int curnum = stack[top].num ;
            51                 int curposi = stack[top].posi ;
            52                 top -- ;
            53                 if( curnum+temp > 0 ) 
            54                 {
            55                     curnum = curnum + temp ;
            56                     mincost += abs(temp) * abs(curposi-node[i].posi) ;
            57                     temp = 0 ;
            58                     stack[++top].num = curnum ; stack[top].posi = curposi ;
            59                 }
            60                 else if( curnum + temp < 0 )
            61                 {
            62                     temp = curnum + temp ;
            63                     mincost += abs(curnum) * abs(curposi-node[i].posi) ;
            64                 }
            65                 else 
            66                 {
            67                     temp = curnum + temp ;
            68                     mincost += abs(curnum) * abs(curposi-node[i].posi) ;
            69                 }
            70             }
            71         }
            72     }//for
            73 
            74     total = 0 ;
            75     forint i=0; i<=top; i++ ) total += stack[i].num ;
            76     printf( "%I64d %I64d\n", sum-total, mincost ) ;
            77 }
            78 
            79 int main()
            80 {
            81     while( scanf( "%d %d"&inn, &ind ) != EOF )
            82     {
            83         input() ;
            84 
            85         process() ;
            86 
            87         //output() ;
            88     }
            89 
            90     return 0 ;
            91 }
            色妞色综合久久夜夜| 99久久国产综合精品麻豆| 久久99精品久久久久久水蜜桃| 久久国产精品一国产精品金尊| 亚洲午夜久久久影院| 99久久99久久久精品齐齐| 久久se这里只有精品| 日日噜噜夜夜狠狠久久丁香五月| 久久精品国产亚洲αv忘忧草| 国产人久久人人人人爽| 亚洲欧美日韩久久精品| 日本一区精品久久久久影院| 国色天香久久久久久久小说| 久久久这里有精品中文字幕| 国产精品视频久久久| 成人午夜精品无码区久久| 久久久久久亚洲精品不卡| 99久久中文字幕| 久久亚洲sm情趣捆绑调教| 91精品国产高清久久久久久国产嫩草| 国产福利电影一区二区三区久久老子无码午夜伦不 | 91秦先生久久久久久久| 国产成人精品久久亚洲高清不卡 | 久久国产高清字幕中文| 人妻无码αv中文字幕久久琪琪布| 久久久久久综合网天天| 成人a毛片久久免费播放| 久久精品国产欧美日韩99热| 国产精品免费久久| 99久久精品免费观看国产| 狠狠色丁香久久婷婷综合五月| 伊人 久久 精品| 天天综合久久一二三区| 久久精品女人天堂AV麻| 91精品国产91久久| 99久久精品国产毛片| 欧美伊香蕉久久综合类网站| 国产午夜久久影院| 久久996热精品xxxx| 一本久久综合亚洲鲁鲁五月天亚洲欧美一区二区| 久久久久一区二区三区|