Maximizing Final Score in a Custom Jeopardy Game with Doubling Questions

In this problem, there are n questions with given point values and m special questions that allow doubling the current score instead of earning their base points. The goal is to arrange the order of answering all questions so that the final score is maximized.

Each question i has a fixed value val[i]. Among them, m indices correspond to doubling questions. When encountering a doubling question, the player may replace its value with a new one between its original value and the current score (exclusive lower bound), then double the entire score instead of adding the question's value. However, since optimal play under perfect conditions is assumed, the strategy simplifies to deciding whether to take the doubling question's value as additive or apply a doubling operation.

The optimal approach:

  1. Sum the points of all non-doubling questions—these must be collected fully because they contribute directly.
  2. Sort the values of the doubling questions in descending order.
  3. Process each doubling question in that sorted order:
    • Let curScore be the score before handling the current doubling question.
    • If adding the current doubling question's value yields more than doubling curScore, take its value as addition.
    • Otherwise, apply the doubling operation.

This greedy method works because doubling grows faster when the current score is large, so we should use the largest doubling-question values early only if they don't surpass the benefit of doubling.

Reasoning behind the condition: Given current score S and a doubling-question value v:

  • Adding: new score = S + v
  • Doubling: new score = S * 2 Choose doubling if S * 2 >= S + v, i.e., S >= v. But because we can adjust v up to S - 1 if needed, the effective comparison becomes: if S + v > S * 2v > S, then addition is better; otherwise, doubling is better. Since we process from largest v downward, once v <= S, all remaining ones should trigger doubling.

Reimplemented solution:

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int totalQ, bonusCount;
    cin >> totalQ >> bonusCount;

    vector<long long> questionValue(totalQ + 1);
    long long baseSum = 0;

    for (int i = 1; i <= totalQ; i++) {
        cin >> questionValue[i];
    }

    vector<int> bonusIndices(bonusCount);
    for (int i = 0; i < bonusCount; i++) {
        cin >> bonusIndices[i];
    }

    // Collect values of doubling questions and exclude them from base sum
    vector<long long> doublingValues;
    for (int idx : bonusIndices) {
        doublingValues.push_back(questionValue[idx]);
    }

    // Base score is sum of all questions except doubling ones
    for (int i = 1; i <= totalQ; i++) {
        bool isDoubling = find(bonusIndices.begin(), bonusIndices.end(), i) != bonusIndices.end();
        if (!isDoubling) {
            baseSum += questionValue[i];
        }
    }

    // Sort doubling values in descending order
    sort(doublingValues.rbegin(), doublingValues.rend());

    long long currentScore = baseSum;
    for (long long val : doublingValues) {
        if (currentScore + val > currentScore * 2) {
            currentScore += val;
        } else {
            currentScore *= 2;
        }
    }

    cout << currentScore << endl;
    return 0;
}

Explanation of sample cases:

  • Case 1: n = 4, m = 1, values = [1, 3, 7, 5], doubling index = 3 (value 7). Base sum without doubling = 1 + 3 + 5 = 9. Compare 9 + 7 = 16 vs 9 × 2 = 18 → choose doubling → result 18.
  • Case 2: n = 3, m = 2, values = [10, 3, 8], doubling indices = 2, 3 (values 3, 8). Base sum = 10. Descending doubling values = [8, 3]. Process 8: 10 + 8 = 18 vs 20 → double to 20. Process 3: 20 + 3 = 23 vs 40 → double to 40 → result 40.
  • Case 3: n = 2, m = 2, values = [100, 200], both doubling. Base sum = 0. Values = [200, 100] sorted. Start 0 + 200 = 200 (since dobuling 0 stays 0). Next: 200 + 100 = 300 vs 400 → double → result 400.

Tags: Dynamic Programming Greedy Algorithm Sorting Game Theory Optimization

Posted on Mon, 08 Jun 2026 16:10:56 +0000 by lorddraco98