vishwakarmavishal1999's blog

By vishwakarmavishal1999, history, 3 years ago, In English

I tried all the types of input and for me, it is giving all the correct answers. on submission it is giving me "Wrong answers" error. I don't know where. IF YOU KNOW WHERE IS IT GETTING WRONG IN MY PROGRAM. HELP ME TO CORRECT IT.

Problem Link : https://atcoder.jp/contests/keyence2021/tasks/keyence2021_a

My code :

#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long int n; cin>>n;
    vector<long long int> a(n);
    vector<long long int> b(n);
    vector<long long int> c(n);
    for(auto &i:a)
    {
        cin>>i;
    }  
    for(auto &i:b)
    {
        cin>>i;
    }  

    long long int max1 = a[0];
    long long int max2 = b[0];
    long long int res, pre_res;
    c[0] = 1LL*max1*max2;

    long long int m = c[0];
    for(long int i = 1 ; i < n; i++)
    {
        pre_res =1LL*max1*max2;
        max1 = max(max1,a[i]);
        if(max1>a[i])
        {
            max2 = max(max2,b[i]);
        }
        else {max2 = b[i];}
        res = 1LL*max1*max2;
        if(res > pre_res)
        {
            c[i] = res;
        }
        else {c[i] = pre_res;}
    }


    for(auto i:c)
    {
        cout<<i<<endl;
    }
    return 0;
}
| Write comment?
»
3 years ago, # |
  Vote: I like it +9 Vote: I do not like it
Try:
2
1 2
2 1
Answer should be '2 4'
 

Maybe you just try this:

for(long int i = 1 ; i < n; i++)
{
   max1=max(max1,a[i]);
   max2=max(max2,b[i]);
   c[i]=max1*max2;
}