제출 #1342012

#제출 시각아이디문제언어결과실행 시간메모리
1342012mehrzad축제 (IOI25_festival)C++17
5 / 100
35 ms5052 KiB
 // Solution for the sub‑task where T[i] = 1 for every coupon.
  // The game reduces to buying as many coupons as possible while the total
  // price does not exceed the initial number of tokens A.
  // The optimal strategy is to purchase coupons in non‑decreasing order of price.

  #include "festival.h"
  #include <bits/stdc++.h>
  using namespace std;

  vector<int> max_coupons(int A, vector<int> P, vector<int> T) {
      int N = (int)P.size();

      // Pair each coupon with its index and price.
      vector<pair<int,int>> coupons;
      coupons.reserve(N);
      for (int i = 0; i < N; ++i) {
          coupons.emplace_back(P[i], i);
      }

      // Sort by price (ascending).
      sort(coupons.begin(), coupons.end(),
           [](const pair<int,int>& a, const pair<int,int>& b) {
               return a.first < b.first;
           });

      long long tokens = A;          // current amount of tokens (use 64-bit)
      vector<int> answer;            // indices of bought coupons in order
      answer.reserve(N);

      for (const auto& cp : coupons) {
          long long price = cp.first;
          if (tokens >= price) {     // we can afford this coupon
              tokens -= price;       // after purchase (T[i] == 1)
              answer.push_back(cp.second);
          } else {
              // All remaining coupons are at least as expensive,
              // therefore we can stop.
              break;
          }
      }

      return answer;                  // maximal number of coupons bought
  }
#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...