# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1102015 | Mo_co_giai_VNOI | Nile (IOI24_nile) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}