This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
vector<vector<long long> >cmp;
vector<long long>num;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long menge , numm , nummer , erg = 0;;
cin >> menge;
for(long long i = 0 ; i < menge; i++){
cin >> numm >> nummer;
if(numm > 0){
cmp.push_back({numm , i});
}
num.push_back(nummer);
}
long long pl = cmp.size() - 1;
for(long long i = menge - 1; i >= 0 ; i--){
while(num[i]){
if(cmp[pl][0] == 0){
pl--;
}
if(pl < 0){
break;
}
nummer = min(num[i], cmp[pl][0]);
num[i] -= nummer;
cmp[pl][0] -= nummer;
erg += nummer * abs(i - cmp[pl][1]);
}
}
cout << erg << "\n";
}
# | 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... |