Submission #817468

# Submission time Handle Problem Language Result Execution time Memory
817468 2023-08-09T12:46:49 Z cig32 Akcija (COCI21_akcija) C++17
30 / 110
38 ms 63012 KB
#include "bits/stdc++.h"
using namespace std;
#define int long long 
#define double long double
const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
  int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
int bm(int b, int p) {
  if(p==0) return 1 % MOD;
  int r = bm(b, p >> 1);
  if(p&1) return (((r*r) % MOD) * b) % MOD;
  return (r*r) % MOD;
}
int inv(int b) { 
  return bm(b, MOD-2);
}
int fastlog(int x) {
  return (x == 0 ? -1 : 64 - __builtin_clzll(x) - 1);
}
void printcase(int i) { cout << "Case #" << i << ": "; }
bool cmp(pair<int, int> x, pair<int, int> y) {
  return x.second < y.second;
}
void solve(int tc) {
  int n, k;
  cin >> n >> k;
  pair<int, int> p[n+1];
  for(int i=1; i<=n; i++) cin >> p[i].first >> p[i].second;
  sort(p+1, p+1+n, cmp);
  pair<int,int> dp[n+1][n+1];
  for(int i=1; i<=n; i++) dp[0][i] = {1e18,0};
  dp[0][0] = {0,1};
  for(int i=1; i<=n; i++) {
    for(int j=0; j<i; j++) {
      dp[i][j] = {1e18,0};
    }
    pair<int,int> opt = {1e18,0};
    for(int j=0; j<i; j++) {
      if(dp[i-1][j].first < opt.first) {
        opt.first = dp[i-1][j].first;
        opt.second = dp[i-1][j].second;
      }
      else if(dp[i-1][j].first == opt.first) {
        opt.second += dp[i-1][j].second;
      }
    }
    for(int j=i; j<=n; j++) {
      if(p[j].second >= i) {
        dp[i][j] = opt;
        dp[i][j].first += p[j].first;
      }
      else {
        dp[i][j] = {1e18, 0};
      }
      if(dp[i-1][j].first < opt.first) {
        opt.first = dp[i-1][j].first;
        opt.second = dp[i-1][j].second;
      }
      else if(dp[i-1][j].first == opt.first) {
        opt.second += dp[i-1][j].second;
      }
    }
  }
  for(int i=n; i>=1; i--) {
    int mn = 1e18;
    for(int j=i; j<=n; j++) mn = min(mn, dp[i][j].first);
    if(mn <= 1e13) {
      cout << i << " " << mn << "\n"; return;
    }
  }
}
int32_t main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int t = 1; //cin >> t;
  for(int i=1; i<=t; i++) solve(i);
}
// 勿忘初衷
# Verdict Execution time Memory Grader output
1 Correct 32 ms 58052 KB Output is correct
2 Correct 36 ms 62972 KB Output is correct
3 Correct 28 ms 53244 KB Output is correct
4 Correct 27 ms 51892 KB Output is correct
5 Correct 32 ms 61816 KB Output is correct
6 Correct 30 ms 51692 KB Output is correct
7 Correct 36 ms 62412 KB Output is correct
8 Correct 32 ms 53692 KB Output is correct
9 Correct 34 ms 51148 KB Output is correct
10 Correct 31 ms 55324 KB Output is correct
11 Correct 0 ms 324 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 58052 KB Output is correct
2 Correct 36 ms 62972 KB Output is correct
3 Correct 28 ms 53244 KB Output is correct
4 Correct 27 ms 51892 KB Output is correct
5 Correct 32 ms 61816 KB Output is correct
6 Correct 30 ms 51692 KB Output is correct
7 Correct 36 ms 62412 KB Output is correct
8 Correct 32 ms 53692 KB Output is correct
9 Correct 34 ms 51148 KB Output is correct
10 Correct 31 ms 55324 KB Output is correct
11 Correct 0 ms 324 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 36 ms 57988 KB Output is correct
15 Correct 36 ms 63012 KB Output is correct
16 Correct 34 ms 53204 KB Output is correct
17 Correct 27 ms 51924 KB Output is correct
18 Correct 31 ms 61804 KB Output is correct
19 Correct 32 ms 51684 KB Output is correct
20 Correct 38 ms 62404 KB Output is correct
21 Correct 31 ms 53636 KB Output is correct
22 Correct 28 ms 51144 KB Output is correct
23 Correct 31 ms 55252 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 36 ms 57940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 58052 KB Output is correct
2 Correct 36 ms 62972 KB Output is correct
3 Correct 28 ms 53244 KB Output is correct
4 Correct 27 ms 51892 KB Output is correct
5 Correct 32 ms 61816 KB Output is correct
6 Correct 30 ms 51692 KB Output is correct
7 Correct 36 ms 62412 KB Output is correct
8 Correct 32 ms 53692 KB Output is correct
9 Correct 34 ms 51148 KB Output is correct
10 Correct 31 ms 55324 KB Output is correct
11 Correct 0 ms 324 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 36 ms 57988 KB Output is correct
15 Correct 36 ms 63012 KB Output is correct
16 Correct 34 ms 53204 KB Output is correct
17 Correct 27 ms 51924 KB Output is correct
18 Correct 31 ms 61804 KB Output is correct
19 Correct 32 ms 51684 KB Output is correct
20 Correct 38 ms 62404 KB Output is correct
21 Correct 31 ms 53636 KB Output is correct
22 Correct 28 ms 51144 KB Output is correct
23 Correct 31 ms 55252 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 340 KB Output is correct
27 Incorrect 36 ms 57940 KB Output isn't correct
28 Halted 0 ms 0 KB -