# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
500673 |
2021-12-31T18:28:46 Z |
600Mihnea |
Sails (IOI07_sails) |
C++17 |
|
1000 ms |
2124 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
int gauss(int x) {
return x * (x + 1) / 2;
}
struct Data {
int total;
int need;
};
bool operator < (Data a, Data b) {
return a.total < b.total;
}
const int N = (int) 1e5 + 7;
const int INF = (int) 1e18;
int n;
int cnt[N];
Data guys[N];
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
//freopen ("input", "r", stdin);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> guys[i].total >> guys[i].need;
}
set<int> nez;
sort(guys + 1, guys + n + 1);
for (int i = 1; i <= n; i++) {
cnt[0] += (guys[i].total - guys[i - 1].total);
if (cnt[0]) {
nez.insert(0);
}
int need = guys[i].need;
vector<pair<int, int>> after;
auto it = nez.begin();
vector<int> del;
while (need) {
assert(it != nez.end());
int s = *it;
int take = min(need, cnt[s]);
cnt[s] -= take;
assert(take > 0);
if (cnt[s] == 0) {
del.push_back(s);
}
need -= take;
after.push_back({s + 1, take});
it++;
}
assert(need == 0);
for (auto &it : del) {
nez.erase(it);
}
for (auto &it : after) {
cnt[it.first] += it.second;
nez.insert(it.first);
}
}
int sol = 0;
for (int i = 1; i <= n; i++) {
sol += cnt[i] * gauss(i - 1);
}
cout << sol << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
6 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
416 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1079 ms |
664 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1093 ms |
1256 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1089 ms |
1364 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1086 ms |
1728 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1094 ms |
2020 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1057 ms |
2124 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |