Submission #1087083


Source Code Expand

#include<stdio.h>
#include<algorithm>
using namespace std;
struct point {
    int b, e;
    bool operator<(const point &p)const{
        return e-b<p.e-p.b;
    }
}w[5010];
int n;
long long Res, D[5010][5010];
int main(){
    int i, be, j;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d%d",&w[i].b,&w[i].e);
        w[i].b = -w[i].b;
    }
    sort(w+1,w+n+1);
    Res = 1e18;
    for(i=0;i<=n;i++)for(j=0;i+j<=n;j++)D[i][j]=1e18;
    D[0][0] = 0;
    for(i=0;i<n;i++){
        for(j=0;j+i<n;j++){
            int x = n-i-j;
            D[i+1][j] = min(D[i+1][j], D[i][j] + w[x].e + 1ll*(w[x].e-w[x].b)*i);
            D[i][j+1] = min(D[i][j+1], D[i][j] + -w[x].b + 1ll*(w[x].e-w[x].b)*j);
        }
    }
    if(n%2==0){
        for(i=0;i<=n;i++)Res = min(Res, D[i][n-i]);
        while(1){}
        printf("%lld\n",Res);
    }
    else{
        printf("%lld\n",D[n/2][n/2] + 1ll*(w[1].e-w[1].b)*(n/2));
    }
}

Submission Info

Submission Time
Task F - Intervals
User ainta
Language C++14 (GCC 5.4.1)
Score 0
Code Size 963 Byte
Status WA
Exec Time 2111 ms
Memory 116864 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:14:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
./Main.cpp:16:38: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&w[i].b,&w[i].e);
                                      ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1000
Status
TLE × 2
AC × 5
WA × 1
TLE × 39
Set Name Test Cases
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt TLE 2111 ms 116864 KB
001.txt TLE 2105 ms 25856 KB
002.txt TLE 2111 ms 116864 KB
003.txt WA 129 ms 90880 KB
004.txt TLE 2111 ms 116864 KB
005.txt AC 69 ms 48256 KB
006.txt TLE 2111 ms 116864 KB
007.txt TLE 2107 ms 60928 KB
008.txt TLE 2111 ms 116864 KB
009.txt TLE 2104 ms 14592 KB
010.txt TLE 2111 ms 116864 KB
011.txt TLE 2107 ms 53120 KB
012.txt TLE 2111 ms 116864 KB
013.txt TLE 2103 ms 12416 KB
014.txt TLE 2111 ms 116864 KB
015.txt AC 37 ms 26112 KB
016.txt TLE 2111 ms 116864 KB
017.txt TLE 2109 ms 89216 KB
018.txt TLE 2111 ms 116864 KB
019.txt AC 83 ms 58112 KB
020.txt AC 1 ms 128 KB
021.txt AC 1 ms 128 KB
022.txt TLE 2111 ms 116864 KB
023.txt TLE 2111 ms 116864 KB
024.txt TLE 2111 ms 116864 KB
025.txt TLE 2111 ms 116864 KB
026.txt TLE 2111 ms 116864 KB
027.txt TLE 2111 ms 116864 KB
028.txt TLE 2111 ms 116864 KB
029.txt TLE 2111 ms 116864 KB
030.txt TLE 2111 ms 116864 KB
031.txt TLE 2111 ms 116864 KB
032.txt TLE 2111 ms 116864 KB
033.txt TLE 2111 ms 116864 KB
034.txt TLE 2111 ms 116864 KB
035.txt TLE 2111 ms 116864 KB
036.txt TLE 2111 ms 116864 KB
037.txt TLE 2111 ms 116864 KB
038.txt TLE 2111 ms 116864 KB
039.txt TLE 2111 ms 116864 KB
040.txt TLE 2111 ms 116864 KB
041.txt TLE 2111 ms 116864 KB
042.txt TLE 2111 ms 116864 KB
example0.txt TLE 2102 ms 128 KB
example1.txt TLE 2102 ms 256 KB