Skip to content

Commit

Permalink
Merge pull request #5063 from Sosuke23/fix
Browse files Browse the repository at this point in the history
formatting
  • Loading branch information
SansPapyrus683 authored Jan 21, 2025
2 parents 53c142e + ac902ac commit adf6010
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions solutions/silver/cf-1223C.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ Let's try to determine the maximum contribution attainable with $t$ tickets.

The problem indicates that only $x\%$ of the $a$-th ticket and $y\%$ of the $b$-th ticket could contribute to the total ecological contribution. We can precompute these multipliers $pct$ (either $0$, $x$, $y$, or $x+y$ depending on the ticket) over $t$ tickets, then greedily match the largest multiplier with the highest value ticket. This can be done by sorting the multipliers $pct$ and tickets $p$ in decreasing order; then the maximum total ecological contribution would be $\sum\limits_{i=1}^{t} p_i \cdot pct_i$.

## Implementation

**Time Complexity:** $\mathcal{O}(N\log^2 N)$

<LanguageSection>

<CPPSection>

### C++ Implementation

```cpp
#include <bits/stdc++.h>

Expand All @@ -35,19 +33,19 @@ vector<ll> p;

ll x, a, y, b, k;

bool works(int sellTickets) {
vector<ll> percentages(sellTickets);
bool works(int sell_tickets) {
vector<ll> percentages(sell_tickets);

// Add x% to every a-th ticket.
for (int i = a - 1; i < sellTickets; i += a) { percentages[i] += x; }
for (int i = a - 1; i < sell_tickets; i += a) { percentages[i] += x; }

// Add y% to every b-th ticket
for (int i = b - 1; i < sellTickets; i += b) { percentages[i] += y; }
for (int i = b - 1; i < sell_tickets; i += b) { percentages[i] += y; }

sort(percentages.begin(), percentages.end(), greater<ll>());

ll cur = 0;
for (int i = 0; i < sellTickets; i++) { cur += percentages[i] * p[i] / 100; }
for (int i = 0; i < sell_tickets; i++) { cur += percentages[i] * p[i] / 100; }

return cur >= k;
}
Expand Down Expand Up @@ -85,11 +83,8 @@ int main() {
```

</CPPSection>

<JavaSection>

### Java Implementation

```java
import java.io.BufferedReader;
import java.io.IOException;
Expand Down Expand Up @@ -157,11 +152,8 @@ public final class SaveNature {
```
</JavaSection>
<PySection>
### Python Implementation
```py
from math import gcd
Expand Down Expand Up @@ -209,5 +201,4 @@ for _ in range(int(input())):
```

</PySection>

</LanguageSection>

0 comments on commit adf6010

Please sign in to comment.