Блог пользователя lanobezkari

Автор lanobezkari, 20 месяцев назад, По-английски

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.

Полный текст и комментарии »

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

Автор lanobezkari, история, 22 месяца назад, По-английски

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.

Полный текст и комментарии »

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

Автор lanobezkari, история, 23 месяца назад, По-английски

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?

Полный текст и комментарии »

  • Проголосовать: нравится
  • +11
  • Проголосовать: не нравится