Submission #221199

# Submission time Handle Problem Language Result Execution time Memory
221199 2020-04-09T16:46:05 Z Haunted_Cpp Džumbus (COCI19_dzumbus) C++17
0 / 110
49 ms 1272 KB
#include <bits/stdc++.h> 
 
#pragma GCC optimize ("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
 
#define FOR(i, a, b) for(int i = a; i < (int) b; i++)
#define F0R(i, a) FOR (i, 0, a)
#define ROF(i, a, b) for(int i = a; i >= (int) b; i--)
#define R0F(i, a) ROF(i, a, 0)
#define GO(i, a) for (auto i : a)
 
#define rsz resize
#define eb emplace_back
#define pb push_back
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define f first
#define s second
 
using namespace std;
using namespace std::chrono;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;
 
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int ms[] = {+31, +29, +31, 30, +31, +30, +31, +31, +30, +31, +30, +31};

const int N = 1e3 + 5;

struct E {
  int st, et;
  i64 custo;
  int profit;
  bool operator < (E Other) const {
    return custo * (profit == 1 ? 2 : 1) < Other.custo * (Other.profit == 1 ? 2 : 1);
  }
};

i64 cost [N];
bool paid [N];

vvi g (N);

int main () {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  F0R (i, n) cin >> cost[i];
  vector<E> edge (m);
  F0R (i, m) {
    int st, et;
    cin >> st >> et;
    --st; --et;
    g[st].eb(et);
    g[et].eb(st);
    E add = {st, et, cost[st] + cost[et], 2};
    edge[i] = add;
  }
  sort (all(edge));
  vector<pair<i64, int> > ans;
  i64 cur = 0;
  int score = 0;
  while (!edge.empty()) {
    cur += edge.front().custo;
    score += edge.front().profit;
    ans.eb(cur, score);
    paid[edge.front().st] = paid[edge.front().et] = true;
    vector<E> Get;
    F0R (i, n) {
      int st = i;
      GO (et, g[st]) {
        if (paid[st] && paid[et]) continue;
        int profit = !paid[st] + !paid[et];
        E add = {st, et, cost[st] * !paid[st] + cost[et] * !paid[et], profit};
        Get.eb(add);
      }
    }
    sort (all(Get));
    edge = Get;
  }
  int q;
  cin >> q;
  while (q--) {
    int budget;
    cin >> budget;
    if (ans.empty() || budget < ans.front().f) {
      cout << 0 << '\n';
      continue;
    }
    int lo = 0, hi = sz(ans);
    while (lo < hi) {
      int mid = lo + (hi - lo) / 2;
      if (ans[mid].f > budget) hi = mid;
      else lo = mid + 1;
    }
    cout << ans[hi - 1].s << '\n';
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 40 ms 632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 40 ms 632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 49 ms 1272 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 40 ms 632 KB Output isn't correct
2 Halted 0 ms 0 KB -