## Problem:

http://assets.codeforces.com/rounds/1090/a73f8d/en.pdf

## Problem A. Company Merging

#include <bits/stdc++.h>

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

int n; std::cin >> n;
std::vector<int> arr(n), cnt(n);
int tar = 0;
for (int i = 0, k; i < n; ++i) {
std::cin >> k;
cnt[i] = k;
int max = 0;
for (int i = 0, x; i < k; ++i) {
std::cin >> x;
max = std::max(max, x);
}
tar = std::max(tar, max);
arr[i] = max;
}

long long ans = 0;
for (int i = 0; i < n; ++i) ans += 1ll * (tar - arr[i]) * cnt[i];

std::cout << ans << '\n';
return 0;
}

## Problem B. LaTeX Expert

#include <bits/stdc++.h>

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

std::string str, art;
std::vector<std::pair<std::string, int>> vec;
while (getline(std::cin, str)) {
if (str == "\\begin{thebibliography}{99}") {
vec.push_back({str, (int)vec.size()});
break;
}
art += str;
}

int tot = 0; bool flag = false;
std::string name;
std::map<std::string, int> order;
for (auto &c : art) {
if (c == '{') {
flag = true;
name.clear();
continue;
}
if (c == '}') {
order[name] = ++tot;
flag = false;
}
if (flag) name += c;
}

bool suc = true;
while (getline(std::cin, str)) {
if (str == "\\end{thebibliography}") {
vec.push_back({str, (int)vec.size()});
break;
}
std::string name; flag = false;
for (auto &c : str) {
if (c == '{') {
flag = true;
continue;
}
if (c == '}') {
if (order[name] != (int)vec.size()) suc = false;
vec.push_back({str, order[name]});
flag = false;
}
if (flag) name += c;
}
}

if (suc) {
std::cout << "Correct" << '\n';
return 0;
}

std::cout << "Incorrect" << '\n';
std::sort(vec.begin(), vec.end(), [&](std::pair<std::string, int> k1, std::pair<std::string, int> k2) {
return k1.second < k2.second;
});
for (auto &s : vec) std::cout << s.first << '\n';
return 0;
}

## Problem D. Similar Arrays

#include <bits/stdc++.h>

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

int n, m; std::cin >> n >> m;

std::set<std::pair<int, int>> e;

for (int i = 1, u, v; i <= m; ++i) {
std::cin >> u >> v;
e.insert({u, v});
e.insert({v, u});
}

for (int i = 1; i <= n; ++i) {
for (int j = i + 1; j <= n; ++j) {
if (e.find({i, j}) != e.end()) continue;
std::cout << "YES" << '\n';
int cur = 1;
for (int k = 1; k <= n; ++k) {
if (k == i) {
std::cout << n << ' ';
continue;
}
if (k == j) {
std::cout << n - 1 << ' ';
continue;
}
std::cout << cur++ << ' ';
}
std::cout << '\n';
cur = 1;
for (int k = 1; k <= n; ++k) {
if (k == i || k == j) {
std::cout << n << ' ';
continue;
}
std::cout << cur++ << ' ';
}
std::cout << '\n';
return 0;
}
}

std::cout << "NO" << '\n';
return 0;
}

## Problem M. The Pleasant Walk

#include <bits/stdc++.h>

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

int n, k; std::cin >> n >> k;
int len = 1, last = -1, ans = 1;
for (int i = 0, x; i < n; ++i) {
std::cin >> x;
if (last == -1) {
last = x;
continue;
}
if (x == last) len = 1;
else ++len;
ans = std::max(ans, len);
last = x;
}

std::cout << ans << '\n';
return 0;
}
Last modification：April 25th, 2019 at 02:31 pm