#pragma region cp-helper
#include <bits/stdc++.h>
using namespace std;
#define AC ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define lll pair<ll, ll>
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vll vector<lll>
#define vvl vector<vl>
#define vii vector<ii>
#define all(a) a.begin(), a.end()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(a, b)
#define umap unordered_map
#define uset unordered_set
#define nl '\n'
#define fileio(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
#define qmod %mod
#define pls int
#define give main()
const int mod = 1000000007;
#pragma endregion
const int N = 1005;
int n, ans;
pair<int, ii> arr[N];
pls give {
AC;
cin >> n;
for (int i=0; i<n; i++) {
cin >> arr[i].first >> arr[i].second.first;
arr[i].second.second = i;
}
sort(arr, arr+n, [](pair<int, ii> a, pair<int, ii> b) {
return a.second.first > b.second.first;
});
for (int i=1; i<n; i++) {
for (int j=0; j<i; j++) {
int avail = arr[j].second.first - arr[j].first;
if (avail >= arr[i].first) {
arr[j].first += arr[i].first;
arr[i].first = 0;
} else {
arr[j].first = arr[j].second.first;
arr[i].first -= avail;
}
}
}
sort(arr, arr+n, [](pair<int, ii> a, pair<int, ii> b) {
return a.second.second < b.second.second;
});
for (int i=0; i<n; i++) if (!arr[i].first) ans++;
cout << ans << nl;
for (int i=0; i<n; i++) cout << arr[i].first << ' ';
}
Compilation message
psk.cpp:1:0: warning: ignoring #pragma region cp [-Wunknown-pragmas]
#pragma region cp-helper
psk.cpp:30:0: warning: ignoring #pragma endregion [-Wunknown-pragmas]
#pragma endregion
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
6 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
248 KB |
Output is correct |
8 |
Correct |
7 ms |
376 KB |
Output is correct |
9 |
Correct |
6 ms |
376 KB |
Output is correct |
10 |
Correct |
7 ms |
376 KB |
Output is correct |