#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define ull unsigned long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define siz(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//mt19937 mt;void random_start(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
//ll los(ll a, ll b) {return a + (mt() % (b-a+1));}
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9+7;
ll pref[2001];
ll suf[2002];
ll poz[2002];
ll dp[2002][2002][2][2];
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//random_start();
int n,L;
cin >> n >> L;
poz[0] = -1e8;
map<int,int> cnt_map;
rep(i,n)
{
int x;
cin >> x;
cnt_map[x]++;
}
if(siz(cnt_map) > 2000)
{
int q;
cin >> q;
rep(i,q)
{
int a,b,c;
cin >> a >> b >> c;
cout << "No\n";
}
return 0;
}
int cur = 1;
forall(it,cnt_map)
{
poz[cur] = it.ff;
pref[cur] = it.ss;
suf[cur] = it.ss;
cur++;
}
n = cur-1;
poz[n+1] = 1e8;
rep2(i,1,n)
{
pref[i] += pref[i-1];
}
for(int i = n; i >= 1; i--)
{
suf[i] += suf[i+1];
}
rep2(i,0,n)
{
rep2(j,0,n)
{
rep(d1,2)
{
rep(d2,2)
{
dp[i][j][d1][d2] = 1e9;
}
}
}
}
dp[1][0][0][0] = 0;
dp[0][1][1][1] = 0;
rep2(prf,0,n-1)
{
rep2(sf,0,n-1)
{
rep(start,2)
{
if(prf + sf >= n) continue;
//pref add
dp[prf+1][sf][start][0] = min({dp[prf+1][sf][start][0],(prf != 0 ? dp[prf][sf][start][0] + abs(poz[prf+1] - poz[prf]) * (pref[prf] + suf[n+1-sf] +1) : (int)1e9),(sf != 0 ? dp[prf][sf][start][1] + abs(poz[n-sf+1] - poz[prf+1]) * (pref[prf] + suf[n+1-sf]+1) : (int)1e9)});
// suf add
dp[prf][sf+1][start][1] = min({dp[prf][sf+1][start][1],(prf != 0 ? dp[prf][sf][start][0] + abs(poz[n-sf] - poz[prf]) * (pref[prf] + suf[n+1-sf] +1) : (int)1e9),(sf != 0 ? dp[prf][sf][start][1] + abs(poz[n-sf+1] - poz[n-sf]) * (pref[prf] + suf[n+1-sf]+1) : (int)1e9)});
}
}
}
int q;
cin >> q;
rep(qq,q)
{
int p,k,t;
cin >> p >> k >> t;
int l = 0;
int r = n;
int ans = 0;
while(l <= r)
{
int mid = (l+r)/2;
if(poz[mid] <= k)
{
ans = mid;
l = mid+1;
}
else
{
r = mid-1;
}
}
ll cost = pref[n] + min({dp[ans][n-ans][0][0] + abs(p-poz[1]) + abs(k - poz[ans]) * (pref[n]+1),dp[ans][n-ans][0][1] + abs(p-poz[1]) + abs(k-poz[ans+1])* (pref[n]+1),dp[ans][n-ans][1][0] + abs(p-poz[n]) + abs(k-poz[ans])* (pref[n]+1),dp[ans][n-ans][1][1] + abs(p-poz[n]) + abs(k-poz[ans+1])* (pref[n]+1)});
// cout << dp[ans][n-ans][0][0]+ abs(p-poz[1]) + abs(k - poz[ans]) * (pref[n]+1) << " " << dp[ans][n-ans][0][1] << " " << dp[ans][n-ans][1][0] << " " << dp[ans][n-ans][1][1] << " " << pref[n]<< " costs\n";
if(cost <= t) cout << "Yes\n";
else cout << "No\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |