Can my solution AC this problem?
Разница между en1 и en2, 418 символ(ов) изменены
Hello Codeforces,↵
=================↵

Although i did not participate in [Educational Codeforces round 190](https://mirror.codeforces.com/contest/2230/). I have tried to solve its first problem, https://mirror.codeforces.com/contest/2230/problem/A . ↵

The core of the problem says that:↵

_There are $n$ students whom have access to keys of cost $a$ and $b$ , which are individual keys and group keys for an online course. For which, a group can be up to three. Our task is to minimize spending for all $n$ students, getting each one a key._↵

Now, if all $n$ kids need to have keys, then we can work by using the group keys for groups of 3 (max). Then as per the remainder, we can add along either $a$ or $b$ depending which is smaller.↵

#### first part:↵
check whether buying individually for 3 or group wise for 3 (max) is more optimal, spend it on $floor(n/3)$ kids (as we are buying in groups of 3 or 3 individually for max).↵
mathematically : $min(3a, b)*floor(n/3)$↵

#### last part:↵
after optimally buying maximum keys in less price, we check how much more is needed (remainder) and check whether buying individually for 1 or group wise for 1 (min) is better.↵
mathematically : $n \bmod 3 * min(a,b)$↵

**combined:** $min(3a, b)*floor(n/3) + n \bmod 3 * min(a,b)$↵

Heres the code:↵

~~~~~↵
#include <bits/stdc++.h>↵
using namespace std;↵

void solve(){↵
    int n,a,b; cin >>n >>a >>b;↵
    int price = 0;↵
    if(n<3){↵
        price = min(a*n, b);↵
    }↵
    else{↵
        price = min(a*3, b)*(n/3)+(n%3)*(min(a,b));↵
    }↵
    cout << price << endl;↵
}↵

int main() {↵
        ios::sync_with_stdio(false);↵
        cin.tie(NULL);↵
int t; cin >> t;↵
while(t--) solve();↵
}↵
~~~~~↵

Edit: I have not talked about my $if(n<3)$ yet, sorry for that. the assumed exceptions are ${1, 2}$ as first part would become $0$ and the last part would be $n*min(a,b)$ , which causes hindrance if $b<a$ , as b is group based up to 3, we would not need more than one group key, yet still we are calculating $n*b$ . Using $min(a*n, b)$ is more reliable as it does not guarantee that the result must be individual. ↵

its currently in queue (queueforces), so i would like to know if my code is correct, any edges or errors.↵

**Hopefully it AC's!**

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский kilobyte136 2026-05-19 19:52:57 26 Tiny change: 'or errors.\n\n**Hopefully it AC's!**' -> 'or errors.'
en2 Английский kilobyte136 2026-05-19 19:51:33 418
en1 Английский kilobyte136 2026-05-19 19:35:20 1862 Initial revision (published)