#include<bits/stdc++.h>
using namespace std;
const int DIM = 5e4 + 5;
int N;
long long dp[DIM];
pair<int,int> arr[DIM];
int main(){
cin >> N;
for( int i = 1; i <= N; i++ ){
cin >> arr[i].first >> arr[i].second;
if( arr[i].first < 0 ) arr[i].first *= (-1);
if( arr[i].second < 0 ) arr[i].second *= (-1);
}
sort( arr + 1, arr + N + 1 );
for( int i = 1; i <= N; i++ ){
dp[i] = (1LL<<61);
int H = 0;
for( int j = i; j >= 1; j-- ){
H = max( H, arr[j].second );
dp[i] = min( dp[i], dp[j - 1] + 4LL * arr[i].first * H );
}
}
cout << dp[N] << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
252 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
4 ms |
376 KB |
Output is correct |
9 |
Correct |
13 ms |
380 KB |
Output is correct |
10 |
Correct |
29 ms |
504 KB |
Output is correct |