โจทย์
ดูฉบับแปลEach project is [start_day, end_day, reward]. It occupies every day from start_day through end_day, including both endpoints. You can participate in only one project on a day. Choose a subset with the largest total reward. A project starting on another project’s end day conflicts with it.
Implement project_rewards(projects).
Input
projects: Rows of three integers: start day, end day, and reward.
Output
Return the maximum total reward; the chosen projects need not be returned.
เงื่อนไข
1 ≤ projects ≤ 200,000. 1 ≤ start_day ≤ end_day ≤ 1,000,000,000. Rewards are positive integers at most 1,000,000,000.
ตัวอย่าง
อินพุต:
projects = [
[1, 2, 4],
[3, 4, 5],
[2, 3, 10]
]
ผลลัพธ์ที่คาดหวัง:
expected = 10
อินพุต:
std::vector<std::vector<long long>> projects = {
{1, 2, 4},
{3, 4, 5},
{2, 3, 10}
};
ผลลัพธ์ที่คาดหวัง:
long long expected = 10;
อินพุต:
long[][] projects = new long[][] {
new long[] {1, 2, 4},
new long[] {3, 4, 5},
new long[] {2, 3, 10}
};
ผลลัพธ์ที่คาดหวัง:
long expected = 10;
คำอธิบาย
The first two projects earn 9 together. The last earns 10 and conflicts with both, so choose it alone.
อินพุต:
projects = [
[1, 2, 4],
[2, 3, 5]
]
ผลลัพธ์ที่คาดหวัง:
expected = 5
อินพุต:
std::vector<std::vector<long long>> projects = {
{1, 2, 4},
{2, 3, 5}
};
ผลลัพธ์ที่คาดหวัง:
long long expected = 5;
อินพุต:
long[][] projects = new long[][] {
new long[] {1, 2, 4},
new long[] {2, 3, 5}
};
ผลลัพธ์ที่คาดหวัง:
long expected = 5;
คำอธิบาย
Both occupy day 2. Choose only the second, with reward 5.
แหล่งอ้างอิง
โจทย์นี้ปรับให้เหมาะกับ CodeUtility กรุณาทำตามคำชี้แจงและข้อจำกัดด้านบน