Canadian Computing Competition: 2025 Stage 1, Senior #3
You are taking an art class, and your current art assignment is very algorithmic. You have pens, each of which has a single colour, represented by an integer from
to
. Initially, the colour of the
-th pen is given by
. In addition, your pens are pretty, with the
-th pen having a prettiness of
.
For your assignment, you need to create a picture using strokes, each from a pen of a different colour. The prettiness of your picture is the sum of the prettiness of the pens used to create the picture.
Your teacher has given you some room for artistic expression: before you create this pretty picture, you are allowed to change at most one pen to any other colour. After this picture is drawn, the pen will revert back to its original colour.
Your teacher will give you of the marks (
of
total marks) for the art assignment based on creating the prettiest picture you can.
To push your creative limits, your teacher also has more pictures for you to create, which compose the remaining
of the marks (
of
total marks) for your art assignment. Before each picture, there will be one of two possible changes to the set of pens available:
1 i c
indicates that the colour of the-th pen changes to
.
2 i p
indicates that the prettiness of the-th pen changes to
.
The changes are executed sequentially (so the first change modifies the initial setup, the second change modifies the result of applying the first change, and so on).
As in the first picture you created, you are allowed to change the colour of at most one pen before the picture is created. Note that if you do change the colour of one pen, it affects only the next picture you draw, and the pen will revert to its previous colour before the next change is applied (if any).
What is the prettiness of the prettiest pictures you can create?
Input Specification
The first line of input contains three space-separated integers ,
, and
.
The next lines each contain two space-separated integers,
and
, indicating the colour and prettiness of the
-th pen.
The next lines each contain three space-separated integers, beginning with
or
. If the first integer is
, it is followed by two integers
and
, representing a change of the colour of the
-th pen to
. If the first integer is
, it is followed by two integers
and
, representing a change of the prettiness of the
-th pen to
.
It is guaranteed that initially and after each change, there is at least one pen with each of the colours.
The following table shows how the available marks are distributed:
Marks | Bounds on |
Bounds on |
Additional constraints |
---|---|---|---|
5 | None | ||
2 | None | ||
2 | None | ||
2 | None | ||
2 | All prettiness values are distinct | ||
2 | None |
Output Specification
The output is lines, with the
-th line containing one integer, the largest possible prettiness value obtainable after the first
changes have been performed.
Sample Input 1
6 3 0
1 6
2 9
3 4
2 7
3 9
1 3
Sample Output 1
25
Explanation for Sample Output 1
There are six pens available in three different colours. The set of pens is:
- two pens of colour
, with prettiness
and
,
- two pens of colour
, with prettiness
and
,
- two pens of colour
, with prettiness
and
.
If we do not change the colour of any pens, the prettiest picture has prettiness . However, if we change the colour of pen
from colour
to colour
, we can create a picture with prettiness
, which is the prettiest picture that can be created.
Sample Input 2
3 2 2
1 20
2 30
1 10
1 3 2
2 3 25
Sample Output 2
50
50
55
Explanation for Sample Output 2
There are three pens with two different colours available.
Before the first change, using pen and pen
, with colours
and
, respectively, achieves a prettiness of
.
After the first change, pen has colour
. There is no alteration in the maximum prettiness, even if we could switch one pen: picking pens
and
will yield the maximum prettiness.
After the second change, pen will have colour
and prettiness
. Before the final picture is created, we can change the colour of pen
to colour
, and use pens
and
to achieve the maximum prettiness of
.
Comments