Weakness Triplet Counter
Preview mode. Log in to edit, run, submit, and save progress.
Hard
Weakness Triplet Counter
A ranking review receives a sequence of strength scores. A weakness pattern is a triple of positions i < j < k where the scores strictly decrease from left to right. For each sequence, count the number of such triples. Input Format: The first line contains t. Each case contains n followed by n strength scores. Output Format: For each case, print the number of decreasing triples.
Examples
Example 1
Input:
2 5 5 3 4 2 1 4 1 2 3 4
Output:
7
Explanation: The first sequence has several decreasing triples; the increasing sequence has none.
Approach hint
Think of each position as the middle of the triple.
Common mistake
Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.
solution.cpp