ndakostan's blog

By ndakostan, 10 years ago, In English

I try to solve this problem 2B in Java. My class was compiled in Eclipse but when I submited it, Codeforces's verdict is runtime error. I have read other's code in Java but I can't find out the problem. Why did it happen? Here is my code

Full text and comments »

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

By ndakostan, 10 years ago, In English

I am wondering if there is a way to implement 466Cthat use binary search? Can anyone give me an answer.

Full text and comments »

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

By ndakostan, 10 years ago, In English

Problem 457A Test 8 only contains 1 line in input. Is this a wrong test case?

Full text and comments »

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

By ndakostan, 10 years ago, In English

Hello every one.I am newbie on Codeforces. I am trying to solve this problem on Codeforces link. They suggest me using dp and greedy. This is my code and it had wrong answer on test 11. Can any one help me. Thank you so much. ~~~~~

include<bits/stdc++.h>

define MAX 500000

using namespace std;

int N; int X; int c[100]; long a[100]; long l[MAX];

void input(){ ifstream fin("input.txt");

fin>>N;
fin>>X;
for(int i = 0; i < N; i++) fin>>c[i];   
fin.close();

}

void output(int n){ ofstream fout("output.txt"); fout<<n; fout.close(); }

void solution(){

long max;
long maxtong;
long i;
long j;
long sum;
l[0] = 0;
maxtong = 0;

for(i = 1; i <= MAX -1 ; i++) l[i] = -1;

for(i = 0; i < N; i++){
    max = maxtong;
    for(j = maxtong; j >= 0; j--){
       if( j + a[i] > X) continue;
       if(l[j] != -1 && l[j] + 1 > l[j + a[i]]) {
         l[j + a[i]] = l[j] + 1;

         if( max < j + a[i]) max = j + a[i];  
       }
    }
    maxtong = max;
}

}

int main(){ input(); for(int i = 0; i < N; i++) a[i] = c[i] * (N — i);

solution();
for(long i = X; i >= 0; i--) if(l[i] != -1) {
    output(l[i]);
    exit(0);
}

} ~~~~~

Full text and comments »

  • Vote: I like it
  • -12
  • Vote: I do not like it