Submission

Status:

PPPPP

Subtask/Task Score:

100/100

Score: 100

User: Kidmaiok

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

Language: cpp

Time: 0.023 second

Submitted On: 2026-10-15 13:12:19

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define space << ' '
#define nl << endl

vector<pair<string,int>> book;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int l,n;
    cin >> l >> n;
    int total = 0;
    for(int i =0; i < n; i++){
        int x;
        string name;
        cin >> x >> name;
        total += x;
        book.push_back({name,x});
    }
    sort(book.begin(),book.end());

    string choson = "";
    for(int i =0; i < total; i++){
        choson += "+-";
    }
    choson += "+";
    cout << choson << "\n";
    vector<string> book2(total, "");
    bool up = 0;
    int idx = 0;
    for(auto [name1,x1] : book){
        for(int i =0; i < x1; i++){
            for(int j = 0; j < l;j++){
                if(up == 0){
                    if(j < name1.size()){
                    book2[idx]  += name1[j];
                    }else{
                        book2[idx]  += ".";
                    }
                }else{
                    if(l - name1.size() > j){
                        book2[idx]  += ".";
                    }else{
                        book2[idx]  += name1[l - 1 - j];
                    }
                }
                
            }
            idx++;
            up = !up;
        }   
    }
    for(int j = 0; j < l; j++){
        cout << '|';
        for(int i = 0; i < total; i++){
            cout << book2[i][j] << '|';
        }
        cout << '\n';
    }
    cout << choson << '\n';




}