Approach
Sorting and greedy selection
For ABC323 C — World Tour Finals, the implementation first exposes a useful order, then scans that order while making locally justified choices.
- Choose the key that reveals the greedy or grouping structure.
- Sort the relevant records by that key.
- Scan in order, maintaining the invariant that makes each local choice safe.
Code notes
- 46 lines of Python from the credited upstream file abc323_c.py.
- The implementation visibly relies on sequence storage, ordered lookup.
- No explicit loop blocks detected.
Complexity
Sorting is typically the dominant term unless the subsequent scan uses a more expensive nested operation.
Check the problem constraints before deciding whether this complexity will pass.
Use this to learn the idea, then write your own version.
12 3 4def main():5 import sys6 7 input = sys.stdin.readline8 9 n, m = map(int, input().split())10 a = list(map(int, input().split()))11 s = [list(input().rstrip()) for _ in range(n)]12 total_scores = list()13 not_solved_all = list()14 15 for i, si in enumerate(s, 1):16 tmp = 017 not_solved = list()18 19 for j, sij in enumerate(si):20 if sij == "o":21 tmp += a[j]22 else:23 not_solved.append(a[j])24 25 total_scores.append(tmp + i)26 not_solved_all.append(sorted(not_solved, reverse=True))27 28 max_score = max(total_scores)29 30 for i, total_score in enumerate(total_scores):31 count = 032 tmp_score = total_score33 34 for not_solved_i in not_solved_all[i]:35 if tmp_score >= max_score:36 break37 38 tmp_score += not_solved_i39 count += 140 41 print(count)42 43 44if __name__ == "__main__":45 main()46