【CodeForces】[366A]Dima and Guards

Problem Description

Loading...

Problem Analysis

At first glance this looks like a very troublesome problem.
But the advantage of a Special Judge
is that any output satisfying the statement is accepted.

So we only need to find one valid group among the four and output it.
If none exists, output -1.

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#include<stdio.h>
int main() {
	int n;
	while(scanf("%d",&n)!=EOF) {
		int rest=-1,res;
		for(int i=1; i<5; i++) {
			int a,b,c,d;
			scanf("%d %d %d %d",&a,&b,&c,&d);
			if((a<b?a:b)+(c<d?c:d)<=n)
				rest=i,res=(a<b?a:b);
		}
		if(rest==-1)
			printf("-1\n");
		else
			printf("%d %d %d\n",rest,res,n-res);
	}
	return 0;
}

Problem address: 【CodeForces】[366A]Dima and Guards

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...