#include "candies.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
//#define int long long
using i64 = long long;
template <class F, class _S>
bool chmin(F &u, const _S &v){
bool flag = false;
if ( u > v ){
u = v; flag |= true;
}
return flag;
}
template <class F, class _S>
bool chmax(F &u, const _S &v){
bool flag = false;
if ( u < v ){
u = v; flag |= true;
}
return flag;
}
const i64 inf = 1e15;
std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l,
std::vector<int> r, std::vector<int> v) {
int q = l.size(), n = c.size();
vector <int> ans(n);
for ( int i = 0; i < n; i++ ){
vector <int> p;
for ( int j = 0; j < q; j++ ){
if ( l[j] <= i && r[j] >= i ){
p.pb(j);
}
}
int m = p.size();
vector <i64> pf(m + 1);
int lst = -1, t = -1;
for ( int j = 1; j <= m; j++ ){
int u = p[j - 1];
pf[j] = pf[j - 1] + v[u];
{ // min case
bool ok = false;
for ( int k = j - 1; k >= 0; k-- ){
if ( pf[k] < pf[j] ) break;
if ( pf[k] - pf[j] >= c[i] ){
ok = true;
}
}
if ( ok > 0 ){
lst = j, t = 0;
}
}
{ // max case
bool ok = false;
for ( int k = j - 1; k >= 0; k-- ){
if ( pf[k] > pf[j] ) break;
if ( pf[j] - pf[k] >= c[i] ){
ok = true;
}
}
if ( ok > 0 ){
lst = j, t = 1;
}
}
}
if ( lst == -1 ){ // no touch
i64 cnt = 0;
for ( auto &j: p ){
cnt += v[j];
}
cnt -= *min_element(all(pf));
ans[i] = cnt;
} else{
i64 cnt = 0;
for ( int k = lst; k < m; k++ ){
cnt += v[p[k]];
}
cnt += t * c[i];
ans[i] = cnt;
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
348 KB |
Output is correct |
5 |
Correct |
54 ms |
576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5011 ms |
12424 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Execution timed out |
5092 ms |
9568 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Execution timed out |
5097 ms |
11176 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
348 KB |
Output is correct |
5 |
Correct |
54 ms |
576 KB |
Output is correct |
6 |
Execution timed out |
5011 ms |
12424 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |