fun main() {
val t = readLine()!!.toInt()
repeat(t) {
val n = readLine()!!.toInt()
val d = readLine()!!.split(" ").map { it.toInt() }
val maxFirst = d.take(n - 1).maxOrNull()!!
val last = d[n - 1]
if (maxFirst == last - 1) {
println(maxFirst)
} else {
println("Ambiguous")
}
}
}
A
🔥CODECHEF 🔥
TRIANGLE COUNT EASY DONE. ✅ ✅✅✅
TREE CUT XOR.. ✅✅✅
TREE CUT XOR. DONE. ✅✅✅
TREE CUT XOR. ✅✅
DMM
@codercpp001
B Just write first 1 and write from n , n - 1 , .... , 2
For example:
n = 5
Output : 1 5 4 3 2
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
int t;
cin>>t;
while(t--){
int n,d,k;
cin>>n>>d>>k;
//vector<int>v(n+2,0);
int l,r;
map<int,int>start,end;
while(k--){
cin>>l>>r;
start[l]++;
end[r]++;
}
int mom=0,conv=0,bro=0,momind=1,broind=1;
for(int i=1; i<=d; i++){
if(start.find(i)!=start.end()){
conv+=start[i];
}
}
mom=bro=conv;
//cout<<conv<<" ";
for(int i=2; i<=n-d+1; i++){
if(start.find(i+d-1)!=start.end()){
conv+=start[i+d-1];
}
if(end.find(i-1)!=end.end()){
conv-=end[i-1];
}
//cout<<conv<< " ";
if(conv>bro){
bro=conv;
broind=i;
}
if(mom>conv){
mom=conv;
momind=i;
}
}
//cout<<endl;
cout<<broind<<" "<<momind<<endl;
}
}