Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<algorithm>
- using namespace std;
- typedef long long int ll;
- struct edge{
- int h;
- int l,r;
- };
- bool mycmp(edge a,edge b){
- return a.h < b.h;
- }
- int illusion[200010];
- int main()
- {
- // freopen("input_cm03.txt","r",stdin);
- int n,m,k;
- scanf("%d %d %d",&m,&n,&k);
- ll ban[n+1];
- for(int i = 1 ; i <= n ; i ++){
- scanf("%lld ",&ban[i]);
- }
- edge ae[k];
- for(int i = 0 ; i < k ; i ++){
- int l,h;
- scanf("%d %d",&l,&h);
- ae[i] = {h,l,l+1};
- }
- sort(ae,ae+k,mycmp);
- int start;
- scanf("%d",&start);
- int X = start;
- illusion[X - 1] = 1;
- illusion[X + 1] = 1;
- for(int i = 0 ; i < k ; i ++){
- int L = ae[i].l;
- int R = ae[i].r;
- int H = ae[i].h;
- bool check = true;
- swap(illusion[L],illusion[R]);
- if(X == L){
- illusion[L] = 1;
- X = R;
- illusion[X - 1] = 1;
- illusion[X + 1] = 1;
- }
- else if(X == R){
- illusion[R] = 1;
- X = L;
- illusion[X - 1] = 1;
- illusion[X + 1] = 1;
- }
- else if(L-1 >= 1 && X == L - 1){
- illusion[L] = 1;
- }
- else if(R+1 <= n && X == R + 1){
- illusion[R] = 1;
- }
- else{
- check = false;
- }
- //if(check)printf("Test edge #%d : h(%d),at(%d,%d)\n",i,H,L,R);
- }
- ll maxa = ban[X];
- bool stick = false;
- illusion[X-1] = 1;
- illusion[X+1] = 1;
- for(int i = 1 ; i <= n ; i ++){
- // printf("%d ",illusion[i]);
- if(illusion[i] == 1){
- if(ban[i] > maxa){
- maxa = ban[i];
- stick = true;
- }
- }
- }//printf("\n");
- printf("%lld\n%s",maxa,(stick?"USE":"NO"));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement