ritchie_s's blog

By ritchie_s, history, 11 months ago, In English

LINK

could someone please help me do this problem ? Help will be much appreciated

  • Vote: I like it
  • +1
  • Vote: I do not like it

»
11 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by ritchie_s (previous revision, new revision, compare).

»
11 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

my solution:

spoiler
»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

https://cses.fi/paste/40fad8955180834ac5ea97/

Explanation is almost in my comments.

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

my solution with explanation in comments:

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

typedef long long ll;

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<long long> vl;
typedef pair<long long, long long> pl;

#define nl '\n'
#define sp ' '
#define PB push_back
#define MP make_pair
#define fori(i, a, b) for(int i=a; i<=b; i++)
#define sz(x) (int)x.size()
#define rarr(a) for(auto& x: a) cin >> x;
#define all(a) a.begin(), a.end()
#define vecin(name, len) vector<int> name(len); for (auto &_ : name) cin >> _;
#define vecout(v) for (auto _ : v) cout << _ << " "; cout << endl;

inline void fastio(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

inline void solvee(){
    int n, a, b; cin >> n >> a >> b;
    if(a+b>n){
        cout << "NO" << nl;
        return;
    }
    // lets make b sorted and focus on a
    // we want a wins and n - b+a draws // i need to pick the first a wins such that i have enough run way to also make those draws by order matching at the end
    vector<int> p, q(n);
    fori(i, 1, n){
        q[i-1] = i;
    }
    // b a n-(a+b) // breaking the sorted set by number of elements for loss win and draw for player 1
    int j=0;
    fori(i, b+1, b+a){ // a+b
        p.push_back(i);
        if(q[j] >= p[j]){
            cout << "NO" << nl;
            return;
        }
        ++j;
    }
    fori(i, 1, b){
        p.push_back(i);
        if(q[j] <= p[j]){
            cout << "NO" << nl;
            return;
        }
        j++;
    }
    fori(i, a+b+1, n){
        p.push_back(i);
        if(q[j] != p[j]){
            cout << "NO" << nl;
            return;
        }
        j++;
    }
    cout << "YES" << nl;
    vecout(p);
    vecout(q);
}

int main(){
    fastio();
    int t; cin >> t;
    while(t--){
        solvee();
    }
} 
»
8 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Here's a small algo

- check for validity
  - all draws or at least 1 round win for each, (win+lose) rounds shouldn't exceed total rounds
  - a + b == 0 or (a > 0 and b > 0 and a + b <= n)
- compute draws -> n - (a+b)
- fix A cards from 1 -> n
- for B cards i from 1 to n -> (i+a for b times),(i-b for a times),(i for draw times)

Hope u find it helpful