Time Limit: 5000MS | Memory Limit: 65536K | |
Total Submissions: 6609 | Accepted: 2036 |
Description
That was about 2300 years ago. General Tian Ji was a high official in the country Qi. He likes to play horse racing with the king and others.
Both of Tian and the king have three horses in different classes, namely, regular, plus, and super. The rule is to have three rounds in a match; each of the horses must be used in one round. The winner of a single round takes two hundred silver dollars from the loser.
Being the most powerful man in the country, the king has so nice horses that in each class his horse is better than Tian's. As a result, each time the king takes six hundred silver dollars from Tian.
Tian Ji was not happy about that, until he met Sun Bin, one of the most famous generals in Chinese history. Using a little trick due to Sun, Tian Ji brought home two hundred silver dollars and such a grace in the next match.
It was a rather simple trick. Using his regular class horse race against the super class from the king, they will certainly lose that round. But then his plus beat the king's regular, and his super beat the king's plus. What a simple trick. And how do you think of Tian Ji, the high ranked official in China?
Input
Output
Sample Input
3 92 83 71 95 87 74 2 20 20 20 20 2 20 19 22 18 0
Sample Output
200 0 0
Source
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int a[1010],b[1010]; int main() { int n; while(scanf("%d",&n),n) { for(int i=1; i<=n; i++) scanf("%d",&a[i]); for(int i=1; i<=n; i++) scanf("%d",&b[i]); sort(a+1,a+1+n); sort(b+1,b+1+n); int tl=1,tr=n,ql=1,qr=n; int sum=0; while(tl<=tr) { if(a[tl]<b[ql]) { qr--; tl++; sum=sum-200; } else if(a[tl]==b[ql]) { while(tl<=tr&&ql<=qr) { if(a[tr]>b[qr]) { sum+=200; tr--; qr--; } else { if(a[tl]<b[qr]) sum-=200; tl++; qr--; break; } } } else { tl++; ql++; sum=sum+200; } } printf("%d/n",sum); } return 0; }