B - Minimum Sum 〜初めてのSTL set〜

Quiz

https://atcoder.jp/contests/agc005/tasks/agc005_b

Submit

https://atcoder.jp/contests/agc005/submissions/4611400

Note

setをほぼ初めて使った

  • 要素を入れていくと、入れる度に内部でソートされる
  • 値1のindex, 値2のindex... と順にsetに入れつつ答えを計算していく
    • 賢い
  • 途中でlower_boundを使う箇所がある
  • vectorと同様にlower_bound(ALL(A), val) と書いたら手元で通ったが、提出後にTLE
  • なんとsetにはlower_boundというメソッドが生えている
        //auto it = lower_bound(ALL(se), index);
        auto it = se.lower_bound(index);
  • こちらを使えばTLEせずに通った

学び

  • set