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<int> >cmp;
vector<int>num;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int menge , numm , nummer , erg = 0;;
cin >> menge;
for(int i = 0 ; i < menge; i++){
cin >> numm >> nummer;
if(numm > 0){
cmp.push_back({numm , i});
}
num.push_back(nummer);
}
int pl = cmp.size() - 1;
for(int 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... |