codechef PLAYFIT - "fit to play" draft : http://ideone.com/DkPogD
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
int t, n, a[100002], min, max, gap;
scanf("%d", &t);
while(t--) {
max=0; min=1000000; gap=0;
scanf("%d", &n);
for(int i=0; i<n; i++) scanf("%d", &a[i]);
for(int i=0; i<n-1; i++) for(int j=i+1; j<n; j++) if(a[j]-a[i]>gap) gap=a[j]-a[i];
if(gap) printf("%d\n", gap);
else printf("UNFIT\n");
}
return 0;
}
codechef PLAYFIT - "fit to play" solution : http://ideone.com/gME0k4
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main() {
int t, n, a[100002], min, max, gap, b[100002];
scanf("%d", &t);
while(t--) {
max=0; min=1000000; gap=0;
memset(b, 0, sizeof(b));
scanf("%d", &n);
for(int i=0; i<n; i++) {
scanf("%d", &a[i]);
if(a[i]<min) {
min=a[i];
max=a[i];
}
else if(a[i]>max) {
max=a[i];
b[i]=max-min;
}
if(b[i]>gap) gap=b[i];
}
if(gap) printf("%d\n", gap);
else printf("UNFIT\n");
}
return 0;
}
note: the latter code was AC by 6.03 sec, while former was TLE
No comments:
Post a Comment