vishwakarmavishal1999's blog

By vishwakarmavishal1999, history, 7 weeks 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;
}
 
 
 
 
  • Vote: I like it
  • -17
  • Vote: I do not like it

»
7 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by vishwakarmavishal1999 (previous revision, new revision, compare).

»
7 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by vishwakarmavishal1999 (previous revision, new revision, compare).

»
7 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

HEY!!!?!?!

you might wanna learn how to write blogs or just how to ask for help in general: https://codeforces.com/blog/entry/83672

»
6 weeks 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;
}
  • »
    »
    6 weeks ago, # ^ |
    Rev. 3   Vote: I like it 0 Vote: I do not like it

    But the problem is like this if elements of array a and b is a1 a2 b1 b2

    the elements of array c will be c1 = max(a1*b1)

    c2 = max(a1*b1,a1*b2,a2*b2)

    concluding like this the answer of your given example would be 2 2

    correct me if I am wrong