# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
890414 | Sir_Ahmed_Imran | Sails (IOI07_sails) | C++17 | 1067 ms | 5452 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.
///~~~LOTA~~~///
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define ff first
#define ss second
#define ll long long
#define append push_back
#define all(x) (x).begin(),(x).end()
void solve(){
ll n,m,o,p,q,r;
cin>>n;
vector<pair<ll,ll>> v;
for(int i=0;i<n;i++){
cin>>p>>q;
v.append({p,q});
}
sort(all(v));
vector<pair<ll,ll>> Q{{0,v[0].ff}};
o=0;
p=v[0].ff;
vector<pair<ll,ll>> u;
for(auto& i:v){
if(i.ff>p){
if(Q.back().ff==0)
Q.back().ss+=i.ff-p;
else Q.append({0,i.ff-p});
}
while(i.ss>Q.back().ss){
u.append(Q.back());
i.ss-=u.back().ss;
u.back().ff++;
Q.pop_back();
}
if(i.ss){
u.append({Q.back().ff,Q.back().ss-i.ss});
u.append({Q.back().ff+1,i.ss});
}
while(!u.empty()){
if(Q.empty()) Q.append(u.back());
else if(Q.back().ff==u.back().ff)
Q.back().ss+=u.back().ss;
else Q.append(u.back());
u.pop_back();
}
p=i.ff;
}
for(auto& i:Q)
o+=(i.ss*i.ff*(i.ff-1))/2;
cout<<o<<nl;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
solve();
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... |