Official
B - Trick Taking Editorial by en_translator
Actually scan all cards to determine if a card with color \(T\) (and with color of the card played by player \(1\)) is played, what is the greatest rank among such cards, and who played that card; then the winner can be determined as described in the Problem Statement.
One can scan all cards using a loop feature (like a for statement) that is a standard feature in a programming language.
A sample code in C++ language for this problem follows.
#include <iostream>
#include <utility>
using namespace std;
int n, t;
int c[200001], r[200001];
int main(void)
{
cin >> n >> t;
for(int i = 1; i <= n; i++) cin >> c[i];
for(int i = 1; i <= n; i++) cin >> r[i];
pair<int, int> tmax = {-1, -1}, lmax = {-1, -1};
for(int i = 1; i <= n; i++){
if(c[i] == t) tmax = max(tmax, {r[i], i});
if(c[i] == c[1]) lmax = max(lmax, {r[i], i});
}
if(tmax.first != -1) cout << tmax.second << endl;
else cout << lmax.second << endl;
return 0;
}
posted:
last update: