Submission

Status:

PPPPP

Subtask/Task Score:

100/100

Score: 100

User: cyblox_boi

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

Language: cpp

Time: 0.021 second

Submitted On: 2025-10-22 20:13:22

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

void printBanner(int totalBooks) {
	cout << '+';

	for (int i = 0; i < totalBooks; i++) {
		cout << "-+";
	}

	cout << '\n';
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int L, N;
	cin >> L >> N;

	vector<pair<string, int>> books;
	int totalBooks = 0;

	for (int i = 0; i < N; i++) {
		int K;
		string S;
		cin >> K >> S;
		books.push_back({S, K});
		totalBooks += K;
	}

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

	vector<string> shelf(L, string(totalBooks, '.'));
	int col = 0;
	bool down = true;

	for (auto &b : books) {
		string name = b.first;
		int count = b.second;

		for (int k = 0; k < count; k++) {
			string show = name.substr(0, min((int)name.size(), L));

			if (down) {
				for (int i = 0; i < (int)show.size(); i++) {
					shelf[i][col] = show[i];
				}
			} else {
				for (int i = 0; i < (int)show.size(); i++) {
					shelf[L - 1 - i][col] = show[i];
				}
			}

			col++;
			down = !down;
		}
	}

	printBanner(totalBooks);

	for (int r = 0; r < L; r++) {
		cout << '|';
		for (int c = 0; c < totalBooks; c++)
			cout << shelf[r][c] << '|';
		cout << '\n';
	}

	printBanner(totalBooks);

	return 0;
}