#include <bits/stdc++.h>
#define int long long
using namespace std;
using pi = pair<int, int>;
const int mod = 1e9+7;
const int inv4 = 25e7+2;
int calc(int a, int b){
return ((a*(a+1)%mod)*(b*(b+1)%mod)%mod)*inv4%mod;
}
int req_solve(const vector<pi> & data, int n, int floor){
if (n == 0) return 0;
//find the minimum:
int ind = 0, w = 0;
for (int i = 0; i < n; ++i){
if (data[i].first < data[ind].first) ind = i;
w += data[i].second;
}
int res = (calc(data[ind].first, w) - calc(data[ind].first, floor) + mod) % mod;
vector<pi> next;
for (int i = 0; i < n; ++i){
if (data[i].first == data[ind].first){
res = (req_solve(next, next.size(), data[ind].first) + res) % mod;
next.resize(0);
}
else next.push_back(data[i]);
}
return (req_solve(next, next.size(), data[ind].first) + res) % mod;
}
int32_t main(){
int n; cin >> n;
vector<pi> data(n);
for (int i = 0; i < n; ++i) cin >> data[i].first;
for (int i = 0; i < n; ++i) cin >> data[i].second;
cout << req_solve(data, n, 0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
268 KB |
Output is correct |
2 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
268 KB |
Output is correct |
2 |
Incorrect |
2 ms |
332 KB |
Output isn't correct |