Last active
January 9, 2020 15:21
-
-
Save Chgtaxihe/3abf4c039992ed9a37ae8cc9613e650e to your computer and use it in GitHub Desktop.
Codeforces 1257 #Codeforces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t = int(input()) | |
for i in range(t): | |
n, x, a, b = map(int, input().split()) | |
ans = min(abs(a - b) + x, n - 1) | |
print(ans) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def main(): | |
x, y = map(int, input().split()) | |
if x > 3: | |
print("YES") | |
elif x is 1: | |
print("YES" if y is 1 else "NO") | |
else: | |
print("YES" if y <= 3 else "NO") | |
if __name__ == "__main__": | |
t = int(input()) | |
for _ in range(t): | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def main(): | |
n = int(input()) | |
pos = [-1] * (n + 1) | |
val = list(map(int, input().split())) | |
ans = -1 | |
for idx, v in enumerate(val): | |
if pos[v] is not -1: | |
ans = idx - pos[v] + 1 if ans is -1 else min(ans, idx - pos[v] + 1) | |
pos[v] = idx | |
print(ans) | |
if __name__ == "__main__": | |
t = int(input()) | |
for _ in range(t): | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define ll long long | |
#define ull unsigned long long | |
#define Android ios::sync_with_stdio(false), cin.tie(NULL) | |
using namespace std; | |
void redirect_input(){freopen("./input.txt","r",stdin);} | |
void redirect_output(){freopen("./output.txt","w",stdout);} | |
const int maxn = 2e5 + 100; | |
const int layers = 18; | |
int n, m; | |
int monster[maxn]; | |
int mx_pow_for_endur[maxn]; | |
void solve(){ | |
int a, b, pow, end; | |
cin >> n; | |
for(int i=0; i<=n + 1; i++) mx_pow_for_endur[i] = 0; | |
for(int i=0; i<n; i++) | |
cin >> monster[i]; | |
cin >> m; | |
for(int i=0; i<m; i++){ | |
cin >> pow >> end; | |
mx_pow_for_endur[end] = max(mx_pow_for_endur[end], pow); | |
} | |
for(int i=n-1; i>0; i--) | |
mx_pow_for_endur[i] = max(mx_pow_for_endur[i], mx_pow_for_endur[i + 1]); | |
int pos = 0, ans = 0; | |
while(pos < n){ | |
if(monster[pos] > mx_pow_for_endur[1]){ | |
ans = -1; | |
break; | |
} | |
ans++; | |
int pick = 1, cur = pos, mx = 0; | |
while(cur < n){ | |
mx = max(mx, monster[cur]); | |
if(mx_pow_for_endur[pick] < mx) break; | |
pick++; | |
cur++; | |
} | |
pos = cur; | |
} | |
cout << ans << '\n'; | |
} | |
signed main(){ | |
Android; | |
int t; | |
cin >> t; | |
while(t--) | |
solve(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment