Submission #17347948


Source Code Expand

Copy
// #define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
#define SZ(x) (int)((x).size())
const int64 INF = 1LL << 60;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  vector<ii> b(m);
  for (int i = 0; i < m; ++i) {
    cin >> b[i].second >> b[i].first;
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  trace(b);
  vector<int> L(m + 1);
  for (int i = 0; i < m; ++i) {
    L[i + 1] = max(L[i], b[i].second);
  }

  if (a.back() > b[0].first) {
    cout << -1 << '\n';
    return 0;
  }

  vector<int> pre(n + 1);
  vector<int> d(n);
  vector<vector<ii>> g(n);
  int ret = 1 << 30;
  do {
    for (int i = 0; i < n; ++i) pre[i + 1] = pre[i] + a[i];
    for (int i = 0; i < n; ++i) g[i].clear();
    for (int i = 1; i < n; ++i) g[i - 1].push_back({i, 0});
    for (int i = 0; i < n; ++i) {
      for (int j = i + 2; j <= n; ++j) {
        int cur = pre[j] - pre[i];
        int k = lower_bound(b.begin(), b.end(), ii{cur, 0}) - b.begin();
        // trace(i, j - 1, k, L[k]);
        g[i].push_back({j - 1, L[k]});
      }
    }
    fill(d.begin(), d.end(), 0);
    while (true) {
      bool over = true;
      for (int i = 0; i < n; ++i) {
        for (auto& [j, k] : g[i]) {
          if (d[j] < d[i] + k) {
            d[j] = d[i] + k;
            over = false;
          }
        }
      }
      if (over) break;
    }
    ret = min(ret, d[n - 1]);
  } while (next_permutation(a.begin(), a.end()));

  cout << ret << endl;
  return 0;
}

Submission Info

Submission Time
Task C - Camels and Bridge
User cuiaoxiang
Language C++ (Clang 10.0.0)
Score 500
Code Size 3952 Byte
Status AC
Exec Time 178 ms
Memory 3848 KB

Compile Error

./Main.cpp:78:13: warning: unused variable 'INF' [-Wunused-const-variable]
const int64 INF = 1LL << 60;
            ^
./Main.cpp:79:11: warning: unused variable 'MOD' [-Wunused-const-variable]
const int MOD = 1e9 + 7;
          ^
2 warnings generated.

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 4
AC × 64
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
All ng_01.txt, ng_02.txt, ng_03.txt, ng_04.txt, ng_05.txt, ng_06.txt, ng_07.txt, ng_08.txt, ng_09.txt, ng_10.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, small_01.txt, small_02.txt, small_03.txt, small_04.txt, small_05.txt, small_06.txt, small_07.txt, small_08.txt, small_09.txt, small_10.txt, small_11.txt, small_12.txt, small_13.txt, small_14.txt, small_15.txt, small_16.txt, small_17.txt, small_18.txt, small_19.txt, small_20.txt
Case Name Status Exec Time Memory
ng_01.txt AC 154 ms 3844 KB
ng_02.txt AC 150 ms 3808 KB
ng_03.txt AC 150 ms 3828 KB
ng_04.txt AC 150 ms 3764 KB
ng_05.txt AC 151 ms 3716 KB
ng_06.txt AC 16 ms 3108 KB
ng_07.txt AC 21 ms 3096 KB
ng_08.txt AC 17 ms 3096 KB
ng_09.txt AC 23 ms 3152 KB
ng_10.txt AC 7 ms 3064 KB
random_01.txt AC 137 ms 3764 KB
random_02.txt AC 137 ms 3700 KB
random_03.txt AC 177 ms 3704 KB
random_04.txt AC 176 ms 3824 KB
random_05.txt AC 178 ms 3828 KB
random_06.txt AC 177 ms 3816 KB
random_07.txt AC 176 ms 3848 KB
random_08.txt AC 178 ms 3708 KB
random_09.txt AC 176 ms 3848 KB
random_10.txt AC 142 ms 3696 KB
random_11.txt AC 32 ms 3316 KB
random_12.txt AC 33 ms 3264 KB
random_13.txt AC 44 ms 3108 KB
random_14.txt AC 35 ms 3084 KB
random_15.txt AC 47 ms 3188 KB
random_16.txt AC 39 ms 3148 KB
random_17.txt AC 50 ms 3304 KB
random_18.txt AC 48 ms 3156 KB
random_19.txt AC 42 ms 3240 KB
random_20.txt AC 14 ms 3076 KB
random_21.txt AC 5 ms 3216 KB
random_22.txt AC 31 ms 3140 KB
random_23.txt AC 17 ms 3252 KB
random_24.txt AC 17 ms 3164 KB
random_25.txt AC 20 ms 3204 KB
random_26.txt AC 18 ms 3256 KB
random_27.txt AC 26 ms 3252 KB
random_28.txt AC 18 ms 3148 KB
random_29.txt AC 13 ms 3196 KB
random_30.txt AC 18 ms 3144 KB
sample_01.txt AC 4 ms 3160 KB
sample_02.txt AC 2 ms 3112 KB
sample_03.txt AC 3 ms 3028 KB
sample_04.txt AC 23 ms 3156 KB
small_01.txt AC 16 ms 3072 KB
small_02.txt AC 19 ms 3036 KB
small_03.txt AC 6 ms 3072 KB
small_04.txt AC 13 ms 3024 KB
small_05.txt AC 13 ms 3124 KB
small_06.txt AC 8 ms 3156 KB
small_07.txt AC 6 ms 3172 KB
small_08.txt AC 15 ms 3180 KB
small_09.txt AC 19 ms 3176 KB
small_10.txt AC 10 ms 3192 KB
small_11.txt AC 11 ms 3116 KB
small_12.txt AC 27 ms 3124 KB
small_13.txt AC 15 ms 3024 KB
small_14.txt AC 5 ms 3020 KB
small_15.txt AC 11 ms 3124 KB
small_16.txt AC 19 ms 3104 KB
small_17.txt AC 10 ms 3104 KB
small_18.txt AC 13 ms 3024 KB
small_19.txt AC 7 ms 3028 KB
small_20.txt AC 6 ms 3016 KB