lanobezkari's blog

By lanobezkari, 21 month(s) ago, In English

Hi everyone,

I'm trying to solve this problem.

But my program gives wrong answer for this test case:

1
3 85
33 7 85

cause of the error is because normally

ceil(( 100.00 / 85.00 ) * 85.00 ) = 100

but my program returns answer as 101.

I guess its because CPP can't find exact result of ( 100 / 85 ) so it returns ( 100.00 / 85.00 ) * 85.00 ) something like 100.000001 and ceil function rounds the number up.

Is there a way to fix this?

Thanks in advance.

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By lanobezkari, history, 23 months ago, In English

Problem Link

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<int> dp;
map<int,int> mp;
const int mx = 1e5;
int n;

int solver(int range, int sum) {
    if(dp[range] != -1) return dp[range] = max(dp[range], sum);
    if(range > 1e5) return dp[range] = sum;
    if(range == mx) return dp[range] = sum + range * mp[range];
    return dp[range] = max(solver(range+2, sum + (range*mp[range])), solver(range+3, sum + ((range+1)*mp[range+1])));
}

int main() {
    cin>>n;
    dp.resize(1000006,-1);
    int temp;
    for(int i = 0; i<n; i++) {
        cin>>temp;
        mp[temp]++;
    }
    cout<<solver(1,0)<<endl;
    
    return 0;
}

It gives error on Testcase 9. I have no idea about what I'm doing wrong.

Idea of the code is simple. Iterate through 1 to 1e5. Take max(i, i+1).

I'd be glad if you help me. Thanks in advance.

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By lanobezkari, history, 2 years ago, In English

Hi, I'm currently trying to solve baltic olympiad in informatics problems. But I couldn't find any editorial for it. Do you know any official/unofficial editorial for it?

Full text and comments »

  • Vote: I like it
  • +11
  • Vote: I do not like it