β Cakewalk? (Contest)
Cakewalk? (Contest) easy Time Limit: 2 sec Memory Limit: 128000 kB
import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
public static void main(String[] args) {
// Your code here
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int m=sc.nextInt();
int arr[]=new int[m];
for(int i=0;i<m;i++)
{
arr[i]=sc.nextInt();
}
long cnt=0;
for(int i=1;i<=n;i++)
{
for(int j=i+1;j<=n;j++)
{
boolean valid=true;
for(int k=0;k<m;k++)
{
if(i<=arr[k]&&arr[k]<=j)
{
valid=false;
break;
}
}
if(valid)
{
cnt++;
}
}
}
System.out.print(cnt);
}
}Last updated