# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1102009 | Mo_co_giai_VNOI | 나일강 (IOI24_nile) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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];
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);
}
}
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--){
res = INF;
ll y; cin>>y;
Try(1, y);
cout<<res<<el;
}
return 0;
}