Submission #1087103


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?e-b<p.e-p.b:b<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]);
        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 962 Byte
Status WA
Exec Time 187 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
AC × 2
AC × 44
WA × 1
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 AC 186 ms 116864 KB
001.txt AC 42 ms 25856 KB
002.txt AC 186 ms 116864 KB
003.txt WA 146 ms 90880 KB
004.txt AC 186 ms 116864 KB
005.txt AC 78 ms 48256 KB
006.txt AC 187 ms 116864 KB
007.txt AC 99 ms 60928 KB
008.txt AC 187 ms 116864 KB
009.txt AC 24 ms 14592 KB
010.txt AC 187 ms 116864 KB
011.txt AC 86 ms 53120 KB
012.txt AC 186 ms 116864 KB
013.txt AC 21 ms 12416 KB
014.txt AC 186 ms 116864 KB
015.txt AC 43 ms 26112 KB
016.txt AC 187 ms 116864 KB
017.txt AC 144 ms 89216 KB
018.txt AC 186 ms 116864 KB
019.txt AC 95 ms 58112 KB
020.txt AC 1 ms 128 KB
021.txt AC 1 ms 128 KB
022.txt AC 186 ms 116864 KB
023.txt AC 186 ms 116864 KB
024.txt AC 187 ms 116864 KB
025.txt AC 186 ms 116864 KB
026.txt AC 187 ms 116864 KB
027.txt AC 186 ms 116864 KB
028.txt AC 187 ms 116864 KB
029.txt AC 186 ms 116864 KB
030.txt AC 187 ms 116864 KB
031.txt AC 187 ms 116864 KB
032.txt AC 186 ms 116864 KB
033.txt AC 186 ms 116864 KB
034.txt AC 187 ms 116864 KB
035.txt AC 187 ms 116864 KB
036.txt AC 186 ms 116864 KB
037.txt AC 186 ms 116864 KB
038.txt AC 186 ms 116864 KB
039.txt AC 187 ms 116864 KB
040.txt AC 186 ms 116864 KB
041.txt AC 186 ms 116864 KB
042.txt AC 186 ms 116864 KB
example0.txt AC 1 ms 128 KB
example1.txt AC 2 ms 256 KB