P1842 [USACO05NOV]奶牛玩杂技

MIku

规律:$w_1+s_1<w_2+s_2$


      #include<iostream>
      #include<cstdio>
      #include<algorithm>
      using namespace std;
      int n;
      struct c{
          long long w;
          long long s;
      }cow[50005];
      long long ans;
      long long anss=-0x7f7f7f;
      bool cmp(c x,c y){
          return (x.s+x.w)<(y.s+y.w);
      }
      int main(){
          scanf("%d",&n);
          for(int i=1;i<=n;++i){
              scanf("%lld%lld",&cow[i].w,&cow[i].s);
          }
    sort(cow+1,cow+1+n,cmp);
    for(int i=1;i<=n;++i){
        ans+=cow[i-1].w;
        anss=max(anss,ans-cow[i].s);
    //  cout<<anss;
    }
    cout<<anss;
    return 0;
      } 
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇