# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
816909 |
2023-08-09T07:25:07 Z |
박영우(#10128) |
Ants and Sugar (JOI22_sugar) |
C++17 |
|
4000 ms |
4872 KB |
#include <bits/stdc++.h>
#include <cassert>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 101010
#define MAXS 20
#define INF 1000000000
#define bb ' '
#define ln '\n'
#define Ln '\n'
#define MOD 1000000007
vector<pii> ant, sugar;
ll dp[MAX];
ll psum[MAX];
int Q, L;
void solve() {
int N = ant.size();
int M = sugar.size();
if (!N || !M) {
cout << 0 << ln;
return;
}
sort(ant.begin(), ant.end());
sort(sugar.begin(), sugar.end());
int i, j;
for (i = 0; i < M; i++) psum[i] = sugar[i].second;
for (i = 1; i < M; i++) psum[i] += psum[i - 1];
for (i = 0; i < N; i++) dp[i] = 0;
ll mn = 0;
ll sum = 0;
for (i = 0; i < N; i++) {
sum += ant[i].second;
int ind = upper_bound(sugar.begin(), sugar.end(), pii(ant[i].first + L + 1, 0)) - sugar.begin() - 1;
int ind2 = lower_bound(sugar.begin(), sugar.end(), pii(ant[i].first - L, 0)) - sugar.begin();
dp[i] = -ant[i].second;
for (j = ind2; j <= ind; j++) dp[i] += sugar[j].second;
for (j = 0; j < i; j++) {
int ind3 = lower_bound(sugar.begin(), sugar.end(), pii(ant[j].first + L + 1, 0)) - sugar.begin();
int l = max(ind2, ind3);
if (l > 0) dp[i] = min(dp[i], dp[j] - ant[i].second + (psum[ind] - psum[l - 1]));
else dp[i] = min(dp[i], dp[j] - ant[i].second + psum[ind]);
}
mn = min(mn, dp[i]);
}
cout << mn + sum << ln;
}
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
cin >> Q >> L;
int t, x, a;
while (Q--) {
cin >> t >> x >> a;
if (t == 1) ant.emplace_back(x, a);
else sugar.emplace_back(x, a);
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Execution timed out |
4043 ms |
496 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Execution timed out |
4062 ms |
484 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Runtime error |
35 ms |
4872 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Execution timed out |
4043 ms |
496 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |