#include<bits/stdc++.h>
#define maxn 1000000
#define INF LONG_MAX
#define inf 2e18
#define fo(i,x,y) for (ll i=x;i<=y;i++)
#define Fo(i,x,y,c) for (int i=x;i<=y;i+=c)
#define fo_re(i,x,y) for (int i=x;i>=y;i--)
#define Fo_re(i,x,y,c) for (int i=x;i>=y;i-=c)
#define task "LOVE"
#define fast ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define file_init freopen(task".INP","r",stdin); freopen(task".OUT","w",stdout);
#define ll long long
#define str string
#define bo bool
#define vec vector
#define pa pair
#define pll pa<ll,ll>
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define pb push_back
#define el '\n'
// "PRACTICE MAKES PERFECT" //
// - Presented by KHANH NGUYEN - THD High School for the gifted - //
using namespace std;
const ll MOD = 1e9+7;
struct BURU_AKAIBU
{
ll w, a, b;
};
BURU_AKAIBU s[maxn];
ll n, q, cnt, res = INF;
ll x[maxn];
vec<ll> r;
void Try(int i, ll d){
fo(j,1,2){
x[i] = j;
if (x[i-1] == 0) x[i] = 0;
if (i == n){
cnt = 0;
fo(t,1,n)
if(x[t] == 1) cnt+=s[t].a;
else if (x[t] == 2)
if (abs(s[t].w - s[t+1].w) <= d) cnt+=min(s[t].a + s[t+1].a, s[t].b + s[t+1].b);
else cnt+=s[t].a+s[t+1].a;
res = min(res, cnt);
}
else Try(i+1, d);
}
}
vec<ll> calculate_costs(int w, int a, int b, int e){
ll res = INF;
Try(1, e);
r.push_back(res);
}
signed main ()
{
fast;
cin>>n;
fo(i,1,n){
ll w, a, b;
cin>>w>>a>>b;
BURU_AKAIBU B;
B.a = a;
B.b = b;
B.w = w;
s[i] = B;
}
//cout<<"OK"<<el;
cin>>q;
while(q--){
ll y; cin>>y;
int w, a, b;
calculate_costs(w, a, b, y);
}
for(auto c:r) cout<<c<<el;
return 0;
}
Compilation message
nile.cpp: In function 'void Try(int, long long int)':
nile.cpp:50:25: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
50 | else if (x[t] == 2)
| ^
nile.cpp: In function 'std::vector<long long int> calculate_costs(int, int, int, int)':
nile.cpp:63:1: warning: no return statement in function returning non-void [-Wreturn-type]
63 | }
| ^
/usr/bin/ld: /tmp/ccvuKaTE.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccq2JTuI.o:nile.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccvuKaTE.o: in function `main':
grader.cpp:(.text.startup+0x300): undefined reference to `calculate_costs(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status