Submission #1000892


Source Code Expand

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
int bsr(int x) { return 31 - __builtin_clz(x); }

const int MN = 5050;
using P = pair<ll, ll>;
int n;
vector<P> v;

ll calc(int m, int a) {
    if (m == 0) return 0;
    int b = n/2 - ((n-m)-(n/2-a));
    ll ans = TEN(18);
    P p = v[m-1];
    // left
    if (a) {
        ll x = p.first*(a-1);
        x += p.second*(a);
        ans = min(ans, x + calc(m-1, a-1));
    }
    // right
    if (b) {
        ll x = p.first*(b);
        x += p.second*(b-1);
        ans = min(ans, x + calc(m-1, a));
    }
    return ans;
}
int main() {
    ios::sync_with_stdio(0);
    cout << setprecision(20);
    cin >> n;
    for (int i = 0; i < n; i++) {
        ll l, r;
        cin >> l >> r;
        v.push_back(P(l, r));
    }
    sort(v.begin(), v.end(), [&](const P l, const P r){
        return (l.first+l.second) > (r.first+r.second);
    });
    ll ans = 0;
    if (n % 2 == 1) {
        ans += (v[n-1].first+v[n-1].second)*n/2;
        v.pop_back();
        n--;
    }

//    for (auto d: v) {
//        cout << d.first << " " << d.second << endl;
//    }
    cout << ans + calc(n, n/2) << endl;
    return 0;
}

Submission Info

Submission Time
Task F - Intervals
User yosupo
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1601 Byte
Status WA
Exec Time 2102 ms
Memory 896 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1000
Status
AC × 2
AC × 2
WA × 2
TLE × 41
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 2102 ms 896 KB
001.txt TLE 2102 ms 512 KB
002.txt TLE 2102 ms 896 KB
003.txt TLE 2102 ms 768 KB
004.txt TLE 2102 ms 896 KB
005.txt TLE 2102 ms 640 KB
006.txt TLE 2102 ms 896 KB
007.txt TLE 2102 ms 640 KB
008.txt TLE 2102 ms 896 KB
009.txt TLE 2102 ms 384 KB
010.txt TLE 2102 ms 896 KB
011.txt TLE 2102 ms 640 KB
012.txt TLE 2102 ms 896 KB
013.txt TLE 2102 ms 384 KB
014.txt TLE 2102 ms 896 KB
015.txt TLE 2102 ms 512 KB
016.txt TLE 2102 ms 896 KB
017.txt TLE 2102 ms 768 KB
018.txt TLE 2102 ms 896 KB
019.txt TLE 2102 ms 640 KB
020.txt WA 3 ms 256 KB
021.txt WA 3 ms 256 KB
022.txt TLE 2102 ms 896 KB
023.txt TLE 2102 ms 896 KB
024.txt TLE 2102 ms 896 KB
025.txt TLE 2102 ms 896 KB
026.txt TLE 2102 ms 896 KB
027.txt TLE 2102 ms 896 KB
028.txt TLE 2102 ms 896 KB
029.txt TLE 2102 ms 896 KB
030.txt TLE 2102 ms 896 KB
031.txt TLE 2102 ms 896 KB
032.txt TLE 2102 ms 896 KB
033.txt TLE 2102 ms 896 KB
034.txt TLE 2102 ms 896 KB
035.txt TLE 2102 ms 896 KB
036.txt TLE 2102 ms 896 KB
037.txt TLE 2102 ms 896 KB
038.txt TLE 2102 ms 896 KB
039.txt TLE 2102 ms 896 KB
040.txt TLE 2102 ms 896 KB
041.txt TLE 2102 ms 896 KB
042.txt TLE 2102 ms 896 KB
example0.txt AC 3 ms 256 KB
example1.txt AC 13 ms 256 KB