1627B - Not Sitting - CodeForces Solution


games greedy sortings *1300

Please click on ads to support us..

Python Code:

for _ in range(int(input())):
    n, m = map(int, input().split())
    print(*sorted(max(x + y, n - 1 - x + y, x + m - 1 - y, n - 1 - x + m - 1 - y) for x in range(n) for y in range(m)))

C++ Code:

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

#define int long long

void solve()
{
    int n, m, k;
    cin >> n >> m;
    vector<int> v;
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j)
            v.push_back(max(i, n - i - 1) + max(j, m - j - 1));
    sort(v.begin(), v.end());
    for (int i = 0; i < n * m; ++i) 
        cout << v[i] << " ";
    cout << "\n";
}

int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t;
    cin >> t;
    while(t--) solve();
    return 0;
}


Comments

Submit
0 Comments
More Questions

1726C - Jatayu's Balanced Bracket Sequence
1726A - Mainak and Array
1613C - Poisoned Dagger
475B - Strongly Connected City
652B - z-sort
124B - Permutations
1496C - Diamond Miner
680B - Bear and Finding Criminals
1036E - Covered Points
1015D - Walking Between Houses
155B - Combination
1531A - Зингер | color
1678A - Tokitsukaze and All Zero Sequence
896A - Nephren gives a riddle
761A - Dasha and Stairs
1728B - Best Permutation
1728A - Colored Balls Revisited
276B - Little Girl and Game
1181A - Chunga-Changa
1728C - Digital Logarithm
1728D - Letter Picking
792B - Counting-out Rhyme
1195A - Drinks Choosing
5D - Follow Traffic Rules
1272A - Three Friends
1632D - New Year Concert
1400D - Zigzags
716C - Plus and Square Root
412A - Poster
844B - Rectangles