제출 #1255124

#제출 시각아이디문제언어결과실행 시간메모리
1255124madamadam3축제 (IOI25_festival)C++20
5 / 100
59 ms9408 KiB
#include "festival.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using pi = pair<int, int>;

#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ROF(i, a, b) for (int i = a; i >= b; i--)
#define each(a, x) for (auto &a : x)
#define all(x) (x).begin(), (x).end()
#define bg(x) (x).begin()
#define en(x) (x).end()
#define rev(x) reverse(all(x))
#define sz(x) int((x).size())
#define srt(x) sort(all(x))
#define cnt(a, x) count(all(x), a)
#define trace(x) each(a, (x)) cout << a << " "
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound

struct DSU {
  int n; vi par, siz;

  DSU() {};
  DSU(int N) {
    n = N; par.resize(n); siz.assign(n, 1);
    iota(all(par), 0);
  }

  int find(int v) {
    if (par[v] == v) return v;
    return par[v] = find(par[v]);
  }

  void unite(int a, int b) {
    a = find(a); b = find(b);
    if (a != b) {
      if (siz[a] < siz[b]) swap(a, b);
      par[b] = a;
      siz[a] += siz[b];
    }
  }
};

const ll INF = 1e18;
vl p, t;

ll after(ll money, int idx) {
  if (idx == -1) return -1e17;
  if (money - p[idx] < 0) return -1e17;

  return (money - p[idx]) * t[idx];
}

vi max_coupons(int A, vi P, vi T) {
  int n = sz(P);
  p = vl(all(P)), t = vl(all(T));
  ll money = A;

  vi indices(n); iota(all(indices), 0); sort(all(indices), [&](int a, int b) {return P[a] < P[b];});
  deque<int> t1, t2; FOR(i, 0, n) (T[indices[i]] == 1 ? t1 : t2).pb(indices[i]);

  vi ans;
  FOR(i, 0, n) {
    int i1 = t1.empty() ? -1 : t1.front(), i2 = t2.empty() ? -1 : t2.front();
    ll a1 = after(money, i1), a2 = after(money, i2);

    if (a1 < 0 && a2 < 0) break;

    if (a1 > a2) {
      t1.pop_front();
      money = a1;
      ans.pb(i1);
    } else {
      t2.pop_front();
      money = a2;
      ans.pb(i2);
    }

    if (money > INF) money = INF;
  }
  
  return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...