UVa 12032 - The Monkey and the Oiled Bamboo
//Next Codeforces Round #354 (Div. 2)
#include<bits/stdc++.h>
//#include<cstdio>
//#include<iostream>
//#include<algorithm>
//#include<vector>
//#include<cstring>
//#include<cmath>
//#include<map>
using namespace std;
#define fast ios_base::sync_with_stdio(false)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define nl puts("")
#define psb push_back
//#define i64 long long
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
int main()
{
fast;
//freopen("out.txt" , "w" , stdout);
int t , tc=0 , n , x , i , k = -1 , tmpk;
vii v;
cin >> t;
while(t--)
{
v.clear();
k = -1;
cin >> n;
for(i=0; i<n; i++)
{
cin >> x;
v.push_back(x);
}
k = max(k , v[0]);
for(i=1; i<n; i++)
{
k = max(k , v[i] - v[i-1]);
}
tmpk = k;
if(v[0] == k)
{
k--;
}
bool f=false;
for(i=1; i<n; i++)
{
if(v[i] - v[i-1] == k)
{
k--;
}
else
{
if(v[i] - v[i-1] > k)
{
f=true;
break;
}
}
}
cout << "Case " << ++tc << ": ";
if(f)
{
cout << tmpk + 1 << "\n";
}
else
{
cout << tmpk << "\n";
}
}
return 0;
}
#include<bits/stdc++.h>
//#include<cstdio>
//#include<iostream>
//#include<algorithm>
//#include<vector>
//#include<cstring>
//#include<cmath>
//#include<map>
using namespace std;
#define fast ios_base::sync_with_stdio(false)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define nl puts("")
#define psb push_back
//#define i64 long long
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
int main()
{
fast;
//freopen("out.txt" , "w" , stdout);
int t , tc=0 , n , x , i , k = -1 , tmpk;
vii v;
cin >> t;
while(t--)
{
v.clear();
k = -1;
cin >> n;
for(i=0; i<n; i++)
{
cin >> x;
v.push_back(x);
}
k = max(k , v[0]);
for(i=1; i<n; i++)
{
k = max(k , v[i] - v[i-1]);
}
tmpk = k;
if(v[0] == k)
{
k--;
}
bool f=false;
for(i=1; i<n; i++)
{
if(v[i] - v[i-1] == k)
{
k--;
}
else
{
if(v[i] - v[i-1] > k)
{
f=true;
break;
}
}
}
cout << "Case " << ++tc << ": ";
if(f)
{
cout << tmpk + 1 << "\n";
}
else
{
cout << tmpk << "\n";
}
}
return 0;
}
Comments
Post a Comment