結果

問題 No.798 コレクション
ユーザー emthrm
提出日時 2019-03-15 22:14:56
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,692 bytes
コンパイル時間 1,509 ms
コンパイル使用メモリ 129,956 KB
最終ジャッジ日時 2025-01-06 22:24:10
ジャッジサーバーID
(参考情報)
judge4 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 WA * 13
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:56:35: warning: ‘pos’ may be used uninitialized [-Wmaybe-uninitialized]
   56 |       swap(kau.back(), kawanai[pos]);
      |                                   ^
main.cpp:48:9: note: ‘pos’ was declared here
   48 |     int pos; long long mn = LINF;
      |         ^~~

ソースコード

diff #

#include <algorithm>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f, MOD = 1000000007;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*-----------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  int buy = 0, cnt = 0;
  while (cnt < n) {
    ++buy;
    ++cnt;
    if (buy % 2 == 0) ++cnt;
  }
  vector<pair<int, int> > ba(n); REP(i, n) cin >> ba[i].second >> ba[i].first;
  sort(ALL(ba));
  vector<pair<int, long long> > kau(buy), kawanai(n - buy);
  REP(i, buy) kau[i] = ba[i];
  FOR(i, buy, n) kawanai[i - buy] = ba[i];
  long long ans = 0;
  REP(i, buy) {
    int pos; long long mn = LINF;
    REP(j, kawanai.size()) {
      if (kawanai[j].second <= mn) {
        pos = j;
        mn = kawanai[j].second;
      }
    }
    if (kau.back().second > mn) {
      swap(kau.back(), kawanai[pos]);
      sort(ALL(kawanai));
    }
    ans += kau.back().second;
    kau.pop_back();
    if (i & 1 && !kawanai.empty()) kawanai.pop_back();
    for (auto &e : kau) e.second += e.first;
    for (auto &e : kawanai) e.second += e.first;
  }
  cout << ans << '\n';
  return 0;
}
0