# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
906244 | Matjaz | Sails (IOI07_sails) | C++14 | 1038 ms | 3520 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//
// IOI2007Sails.cpp
//
//
// Created by Matjaz Leonardis on 04/12/2023.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
int INF = 100001;
int main(){
int N;
cin >> N;
vector<int> H(N),K(N);
for (int i=0;i<N;i++) cin >> H[i] >> K[i];
vector<pair<int,int> > p(N);
for (int i=0;i<N;i++) p[i] = make_pair(H[i],K[i]);
sort(p.begin(), p.end());
vector<int> S(100005);
int prev = 0;
for (int i=0;i<N;i++){
S[0] += p[i].first - prev;
int k = p[i].second;
int delayed_update = 0;
for (int j=0;;j++){
if (k == 0) break;
if (S[j] >= k){
S[j] -= k;
S[j + 1] += k;
k = 0;
S[j] += delayed_update;
} else {
k -= S[j];
int tmp = S[j];
S[j] = delayed_update;
delayed_update = tmp;
}
}
prev = p[i].first;
/*cout << p[i].first<< " " << p[i].second << endl;
for (int j=0;j<5;j++) cout << S[j] << endl;
cout << endl;*/
}
long long total=0;
for (int i=0;i<S.size();i++){
total += (((long long)i * (i - 1)) / 2) * S[i];
}
cout << total << endl;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |