#include "nile.h"
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <list>
#include <iomanip>
#include <stdlib.h>
#include <time.h>
#include <cstring>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define REP(i,a,b) for(ll i=(ll) a; i<(ll) b; i++)
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define ff first
#define ss second
#define whole(x) x.begin(),x.end()
#define DEBUG(i) cout<<"Pedro "<<i<<endl
#define INF 1000000000000000000LL
#define EPS ((ld)0.00000000001)
#define pi ((ld)3.141592653589793)
#define VV(vvvv,NNNN,xxxx); REP(iiiii,0,NNNN) {vvvv.pb(xxxx);}
ll mod=1000000007;
template<class A=ll>
void Out(vector<A> a) {REP(i,0,a.size()) {cout<<a[i]<<" ";} cout<<endl;}
template<class A=ll>
void In(vector<A> &a, ll N) {A cur; REP(i,0,N) {cin>>cur; a.pb(cur);}}
vector<long long> calculate_costs(vector<int> W, vector<int> A, vector<int> B, vector<int> E)
{
ll Q = E.size(); ll N = A.size();
vector<pl> a;
ll basis = 0LL; REP(i,0,N) {basis+=A[i]; a.pb({W[i],A[i]-B[i]});}
sort(whole(a));
ll D; ll prev;
vector<ll> ans(Q,0);
REP(q,0,Q)
{
D = E[q];
vector<ll> dp(N,0);
REP(i,0,N)
{
if(i>=1) {dp[i]=max(dp[i],dp[i-1]);}
if(i>=1 && a[i].ff-a[i-1].ff<=D) {prev=0; if(i>1) {prev=dp[i-2];} dp[i]=max(dp[i],prev+a[i-1].ss+a[i].ss);}
if(i>=2 && a[i].ff-a[i-2].ff<=D) {prev=0; if(i>2) {prev=dp[i-3];} dp[i]=max(dp[i],prev+a[i-2].ss+a[i].ss);}
}
ans[q]=basis-dp[N-1];
}
return ans;
}
Compilation message
nile.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
2 | #pragma GCC optimization ("O3")
|
nile.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
3 | #pragma GCC optimization ("unroll-loops")
|
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
2 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
2 ms |
508 KB |
Output is correct |
5 |
Correct |
2 ms |
508 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
5828 KB |
Output is correct |
2 |
Correct |
33 ms |
5828 KB |
Output is correct |
3 |
Correct |
27 ms |
5820 KB |
Output is correct |
4 |
Correct |
25 ms |
5992 KB |
Output is correct |
5 |
Correct |
27 ms |
5744 KB |
Output is correct |
6 |
Correct |
29 ms |
5828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
5828 KB |
Output is correct |
2 |
Correct |
29 ms |
5828 KB |
Output is correct |
3 |
Correct |
37 ms |
5828 KB |
Output is correct |
4 |
Correct |
29 ms |
5824 KB |
Output is correct |
5 |
Correct |
31 ms |
5828 KB |
Output is correct |
6 |
Correct |
28 ms |
5828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
2 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
2 ms |
508 KB |
Output is correct |
5 |
Correct |
2 ms |
508 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
508 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
2 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
2 ms |
508 KB |
Output is correct |
5 |
Correct |
2 ms |
508 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
26 ms |
5828 KB |
Output is correct |
8 |
Correct |
33 ms |
5828 KB |
Output is correct |
9 |
Correct |
27 ms |
5820 KB |
Output is correct |
10 |
Correct |
25 ms |
5992 KB |
Output is correct |
11 |
Correct |
27 ms |
5744 KB |
Output is correct |
12 |
Correct |
29 ms |
5828 KB |
Output is correct |
13 |
Correct |
27 ms |
5828 KB |
Output is correct |
14 |
Correct |
29 ms |
5828 KB |
Output is correct |
15 |
Correct |
37 ms |
5828 KB |
Output is correct |
16 |
Correct |
29 ms |
5824 KB |
Output is correct |
17 |
Correct |
31 ms |
5828 KB |
Output is correct |
18 |
Correct |
28 ms |
5828 KB |
Output is correct |
19 |
Correct |
1 ms |
508 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
2 ms |
336 KB |
Output is correct |
25 |
Correct |
44 ms |
5820 KB |
Output is correct |
26 |
Correct |
36 ms |
5840 KB |
Output is correct |
27 |
Correct |
36 ms |
5816 KB |
Output is correct |
28 |
Correct |
35 ms |
5828 KB |
Output is correct |
29 |
Correct |
36 ms |
5828 KB |
Output is correct |
30 |
Correct |
33 ms |
5820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
5828 KB |
Output is correct |
2 |
Correct |
29 ms |
5828 KB |
Output is correct |
3 |
Correct |
37 ms |
5828 KB |
Output is correct |
4 |
Correct |
29 ms |
5824 KB |
Output is correct |
5 |
Correct |
31 ms |
5828 KB |
Output is correct |
6 |
Correct |
28 ms |
5828 KB |
Output is correct |
7 |
Execution timed out |
2060 ms |
7096 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
508 KB |
Output is correct |
6 |
Correct |
2 ms |
508 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
26 ms |
5828 KB |
Output is correct |
9 |
Correct |
33 ms |
5828 KB |
Output is correct |
10 |
Correct |
27 ms |
5820 KB |
Output is correct |
11 |
Correct |
25 ms |
5992 KB |
Output is correct |
12 |
Correct |
27 ms |
5744 KB |
Output is correct |
13 |
Correct |
29 ms |
5828 KB |
Output is correct |
14 |
Correct |
27 ms |
5828 KB |
Output is correct |
15 |
Correct |
29 ms |
5828 KB |
Output is correct |
16 |
Correct |
37 ms |
5828 KB |
Output is correct |
17 |
Correct |
29 ms |
5824 KB |
Output is correct |
18 |
Correct |
31 ms |
5828 KB |
Output is correct |
19 |
Correct |
28 ms |
5828 KB |
Output is correct |
20 |
Correct |
1 ms |
508 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
2 ms |
336 KB |
Output is correct |
26 |
Correct |
44 ms |
5820 KB |
Output is correct |
27 |
Correct |
36 ms |
5840 KB |
Output is correct |
28 |
Correct |
36 ms |
5816 KB |
Output is correct |
29 |
Correct |
35 ms |
5828 KB |
Output is correct |
30 |
Correct |
36 ms |
5828 KB |
Output is correct |
31 |
Correct |
33 ms |
5820 KB |
Output is correct |
32 |
Execution timed out |
2060 ms |
7096 KB |
Time limit exceeded |
33 |
Halted |
0 ms |
0 KB |
- |