#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";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
8 ms |
2056 KB |
Output is correct |
5 |
Correct |
16 ms |
4400 KB |
Output is correct |
6 |
Correct |
61 ms |
19308 KB |
Output is correct |
7 |
Correct |
124 ms |
38260 KB |
Output is correct |
8 |
Correct |
85 ms |
24856 KB |
Output is correct |
9 |
Correct |
81 ms |
22080 KB |
Output is correct |
10 |
Correct |
63 ms |
19888 KB |
Output is correct |
11 |
Correct |
63 ms |
19872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
8 ms |
2056 KB |
Output is correct |
5 |
Correct |
16 ms |
4400 KB |
Output is correct |
6 |
Correct |
61 ms |
19308 KB |
Output is correct |
7 |
Correct |
124 ms |
38260 KB |
Output is correct |
8 |
Correct |
85 ms |
24856 KB |
Output is correct |
9 |
Correct |
81 ms |
22080 KB |
Output is correct |
10 |
Correct |
63 ms |
19888 KB |
Output is correct |
11 |
Correct |
63 ms |
19872 KB |
Output is correct |
12 |
Incorrect |
31 ms |
9780 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |