Submission

Status:

PPPPP

Subtask/Task Score:

100/100

Score: 100

User: scoobydoobydoo

Problemset: ชั้นหนังสือ

Language: cpp

Time: 0.027 second

Submitted On: 2026-10-15 14:16:27

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#define ll long long
#define el << '\n'

int main() {
    cin.tie(0)->sync_with_stdio(0);

    int l, n;
    cin >> l >> n;

    vector<string> books;

    for (int i=0; i<n; i++) {
        int k;
        string name;
        cin >> k >> name;

        for (int j=0; j<k; j++) {
            books.push_back(name);
        }
    }

    sort(books.begin(), books.end());

    int total = books.size();
    for (int i=0; i<total; i++) {
        books[i] += string(l - books[i].size(), '.');

        if (i % 2 == 1) {
            reverse(books[i].begin(), books[i].end());
        }
    }

    string border = "+";
    for (int i=0; i<total; i++) {
        border += "-+";
    }

    cout << border el;

    for (int i=0; i<l; i++) {
        cout << '|';
        
        for (int j=0; j<total; j++) {
            cout << books[j][i] << '|';
        }
        cout el;
    }

    cout << border el;

    return 0;
}