1334C - Circle Of Monsters

Click to show code.


using namespace std;
using ll = long long;
const int NMAX = 3 * 1e5 + 11;
int n;
ll sum, a[NMAX], b[NMAX];
ll solve(void)
{
    ll suma, sumb, mn = LLONG_MAX;
    suma = sumb = 0;
    for (int i = 0; i < n; ++i)
    {
        suma += a[i];
        b[i] = min(b[i], a[(i + 1) % n]);
        sumb += b[i];
        mn = min(mn, b[i]);
    }
    return suma - sumb + mn;
}
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--)
    {
        sum = 0;
        cin >> n;
        for (int i = 0; i < n; ++i)
            cin >> a[i] >> b[i];
        cout << solve() << endl;
    }
    return 0;
}


1334B - Middle Class

Click to show code.


using namespace std;
using ll = long long;
const int NMAX = 1e5 + 11;
int n, x, a[NMAX];
int solve(void)
{
    ll sum = 0;
    for (int i = 0; i < n; ++i)
    {
        sum += a[i];
        if ((sum / ((ll)i + 1)) < (ll)x)
            return i;
    }
    return n;
}
int main(void)
{
    int t;
    cin >> t;
    while (t--)
    {
        cin >> n >> x;
        for (int i = 0; i < n; ++i)
            cin >> a[i];
        sort(a, a + n, greater<int>());
        cout << solve() << endl;
    }
    return 0;
}


1334A - Level Statistics

Click to show code.


using namespace std;
const int NMAX = 100 + 11;
int n, p[NMAX], c[NMAX];
bool solve(void)
{
    int lp, lc, dp, dc;
    lp = lc = 0;
    for (int i = 0; i < n; ++i)
    {
        dp = p[i] - lp;
        dc = c[i] - lc;
        if (dp < 0 or dc < 0 or dp < dc)
            return false;
        lp = p[i];
        lc = c[i];
    }
    return true;
}
int main(void)
{
    int t;
    cin >> t;
    while (t--)
    {
        cin >> n;
        for (int i = 0; i < n; ++i)
            cin >> p[i] >> c[i];
        cout << (solve() ? "YES" : "NO") << endl;
    }
}


1333B - Kind Anton

Click to show code.


using namespace std;
const int NMAX = 1e5 + 11;
int n, a[NMAX], b[NMAX];
bool prefplus[NMAX], prefminus[NMAX];
bool solve(void)
{
    for (int i = n - 1; i >= 0; --i)
    {
        if (b[i] > a[i] and not prefplus[i])
            return false;
        if (b[i] < a[i] and not prefminus[i])
            return false;
    }
    return true;
}
int main(void)
{
    int t;
    cin >> t;
    while (t--)
    {
        cin >> n;
        bool prefix_plus, prefix_minus;
        prefix_minus = prefix_plus = false;
        for (int i = 0; i < n; ++i)
        {
            cin >> a[i];
            prefplus[i] = prefix_plus;
            prefminus[i] = prefix_minus;
            prefix_plus |= (a[i] == 1);
            prefix_minus |= (a[i] == -1);
        }
        for (int i = 0; i < n; ++i)
            cin >> b[i];
        cout << (solve() ? "YES" : "NO") << endl;
    }
    return 0;
}


1333A - Little Artem

Click to show code.


using namespace std;
int main(void)
{
    int t, n, m;
    cin >> t;
    while (t--)
    {
        cin >> n >> m;
        bool black = true;
        for (int row = 0; row < n; ++row)
        {
            for (int col = 0; col < m; ++col)
            {
                if (row == 0 and col == 1 and (n * m) % 2 == 0)
                    cout << (black ? "W" : "B");
                else
                    cout << (black ? "B" : "W");
                black = !black;
            }
            cout << endl;
        }
    }
    return 0;
}


1332B - Composite Coloring

Click to show code.


using namespace std;
const int NMAX = 1000 + 11;
int ccolor;
int colors[NMAX];
map<int, int> rankdiv;
int smallest_div(int x)
{
    if (x % 2 == 0)
        return 2;
    for (int i = 3; i * i <= x; i += 2)
        if (x % i == 0)
            return i;
    return x;
}
int main(void)
{
    int t, n, x, sd;
    cin >> t;
    while (t--)
    {
        rankdiv.clear();
        ccolor = 1;
        cin >> n;
        for (int i = 0; i < n; ++i)
        {
            cin >> x;
            sd = smallest_div(x);
            colors[i] = rankdiv[sd] = (rankdiv[sd] ? rankdiv[sd] : ccolor++);
        }
        cout << ccolor - 1 << endl;
        for (int i = 0; i < n; ++i)
            cout << colors[i] << " ";
        cout << endl;
    }
    return 0;
}


1332A - Exercising Walk

Click to show code.


using namespace std;
int l, r, d, u;
int x, y;
int x1, y1, x2, y2;
inline bool contained(int val, int l1, int l2)
{
    return l1 <= val and val <= l2;
}
bool solve(void)
{
    int xf, yf;
    xf = x + (r - l);
    yf = y + (u - d);
    if (x1 == x2 and (l or r))
        return false;
    if (y1 == y2 and (d or u))
        return false;
    if (contained(xf, x1, x2) and contained(yf, y1, y2))
        return true;
    return false;
}
int main(void)
{
    int t;
    cin >> t;
    while (t--)
    {
        cin >> l >> r >> d >> u;
        cin >> x >> y;
        cin >> x1 >> y1 >> x2 >> y2;
        cout << (solve() ? "YES" : "NO") << endl;
    }
    return 0;
}


1331H - Its Showtime

Click to show code.


using namespace std;
int main(void)
{
    int input, n, mod, lower, ans = 1;
    cin >> input;
    mod = input % 1000;
    n = (input - mod) / 1000;
    lower = (input % 2 == 0 ? 2 : 1);
    cout << n << endl << mod << endl;
    for (int i = n; i >= lower; i -= 2)
        ans = (ans * i) % mod;
    cout << lower << endl;
    cout << ans << endl;
    cout << ans % mod << endl;
    return 0;
}


1331B - Limericks

Click to show code.


using namespace std;
int main(void)
{
    string s;
    int n;
    cin >> s;
    n = s.size();
    cout << (s[n - 1] % 2 == 1) << endl;
    return 0;
}


1331A - Is It Rated

Click to show code.


using namespace std;
int main(void)
{
    cout << "NO\n";
    return 0;
}