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>
typedef long long ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n,l;
cin >> n >> l;
vector<ll> arr(n);
FOR(i,0,n) cin >> arr[i];
sort(arr.begin(), arr.end());
ll q;
cin >> q;
FOR(i,0,q){
ll a,b,t;
cin >> a >> b >> t;
ll ans = 100000000000000000;
ll temp = 0;
ll cur = 1;
ll pos = a;
temp += abs(pos-arr[0]) * cur;
pos = arr[0];
FOR(j,0,n){
if (arr[j] < b){
temp += abs(pos-arr[j]) * cur;
pos = arr[j];
cur += 1;
}else break;
}
temp += abs(pos - arr[n-1]) * cur;
pos = arr[n-1];
FORNEG(j, n-1, -1){
if (arr[j] > b){
temp += abs(pos-arr[j]) * cur;
pos = arr[j];
cur += 1;
}else break;
}
temp += abs(pos - b) * cur;
ans = min(ans, temp);
temp = 0;
cur = 1;
pos = a;
temp += abs(pos - arr[n-1]) * cur;
pos = arr[n-1];
FORNEG(j, n-1, -1){
if (arr[j] > b){
temp += abs(pos-arr[j]) * cur;
pos = arr[j];
cur += 1;
}else break;
}
temp += abs(pos-arr[0]) * cur;
pos = arr[0];
FOR(j,0,n){
if (arr[j] < b){
temp += abs(pos-arr[j]) * cur;
pos = arr[j];
cur += 1;
}else break;
}
temp += abs(pos - b) * cur;
ans = min(ans, temp);
ans += n;
if (ans <= 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... |