fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <math.h>
  5. #include <limits.h>
  6. #include <stack>
  7. #include <queue>
  8. #include <map>
  9. #include <set>
  10. #include <algorithm>
  11. #include <string>
  12. #include <functional>
  13. #include <vector>
  14. #include <numeric>
  15. #include <deque>
  16. #include <utility>
  17. #include <bitset>
  18. #include <iostream>
  19. using namespace std;
  20. typedef long long lint;
  21. typedef long double llf;
  22. typedef pair<int, int> pi;
  23.  
  24. int n;
  25. pi a[10005];
  26. int dp[10005];
  27. int main(){
  28. scanf("%d",&n);
  29. for(int i=1; i<=n; i++){
  30. scanf("%d %d",&a[i].first, &a[i].second);
  31. a[i].second = 2 * abs(a[i].second);
  32. }
  33. sort(a+1,a+n+1);
  34. for(int i=1; i<=n; i++){
  35. int maxp = a[i].second;
  36. dp[i] = 1e9;
  37. for(int j=i-1; j>=0; j--){
  38. dp[i] = min(dp[i], dp[j] + max(a[i].first - a[j+1].first, maxp));
  39. maxp = max(a[j].second, maxp);
  40. }
  41. }
  42. printf("%d",dp[n]);
  43. }
Success #stdin #stdout 0s 3580KB
stdin
Standard input is empty
stdout
Standard output is empty