이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |