[CF]581B - Luxurious Houses
題目:
http://codeforces.com/problemset/problem/581/B
-----------------------------------------------------------------------------------
#include<bits/stdc++.h>
#define N 100050
using namespace std;
int main(void)
{
int n;
while(scanf("%d",&n)!=EOF)
{
int a[N]={0},mxn[N]={0};
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
for(int i=n-1;i>=1;i--)
mxn[i] = max(mxn[i+1],a[i]);
for(int i=0;i<n;i++)
printf("%d ",max(0,mxn[i+1]-a[i]+1));
printf("\n");
}
return 0;
}
http://codeforces.com/problemset/problem/581/B
-----------------------------------------------------------------------------------
#include<bits/stdc++.h>
#define N 100050
using namespace std;
int main(void)
{
int n;
while(scanf("%d",&n)!=EOF)
{
int a[N]={0},mxn[N]={0};
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
for(int i=n-1;i>=1;i--)
mxn[i] = max(mxn[i+1],a[i]);
for(int i=0;i<n;i++)
printf("%d ",max(0,mxn[i+1]-a[i]+1));
printf("\n");
}
return 0;
}
留言
張貼留言