Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- #define MAX_N 100000
- #define INFINIT 20001
- int coloane[MAX_N+1];
- int apasec(int p){
- int maxim2, cp2;
- maxim2=0;
- while(coloane[p]!=INFINIT){
- cp2=p-1;
- while(coloane[cp2]<=coloane[p]){
- maxim2+=coloane[p]-coloane[cp2];
- cp2--;
- }
- p=cp2;
- }
- return maxim2;
- }
- int main()
- {
- ifstream cin("inundatie.in");
- ofstream cout("inundatie.out");
- int maxim, st, dr, mij, rez, minim, cer, n, p, s, poz, h, dif;
- cin>>cer>>n>>p>>s;
- cin>>coloane[1];
- maxim=minim=coloane[1];
- for(int i=2; i<=n; i++){
- cin>>coloane[i];
- minim=min(minim, coloane[i]);
- maxim=max(maxim, coloane[i]);
- }
- coloane[0]=coloane[n+1]=INFINIT;
- if(cer==1)
- cout<<maxim-minim;
- else if(cer==2)
- cout<<apasec(p);
- else if(cer==3){
- st=1;
- dr=n+1;
- while(st<dr){
- mij=(st+dr+1)/2;
- maxim=apasec(mij);
- if(maxim<=s)
- st=mij;
- else
- dr=mij-1;
- }
- cout<<st;
- }else if(cer==4){
- maxim=dif=0;
- h=coloane[p];
- rez=poz=p;
- while(coloane[p]!=INFINIT){
- if(coloane[p]<h){
- dif++;
- p--;
- if(coloane[p]==INFINIT && maxim<=dif){
- maxim=dif;
- rez=poz;
- }
- }else{
- if(maxim<=dif){
- maxim=dif;
- rez=poz;
- }
- while(coloane[p]<=h)
- p--;
- h=coloane[p];
- dif=0;
- poz=p;
- p--;
- }
- }
- cout<<rez;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement