ClumsyBot's blog

By ClumsyBot, history, 20 months ago, In English

978C - Letters

#include<iostream>
#include<sstream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include<functional>
#include<unordered_map>
#include<numeric>

using namespace std;

#define ll long long
#define mod 1e9+7
#define cy std::cout << "YES"<< std::endl
#define cn std::cout << "NO"<< std::endl
#define IN(x) cin >> x;
#define OUT(x) cout << x;
#define all(arr) arr.begin(),arr.end()
#define rep(a,b) for(int i = a;i<b;i++);
#define nline std::cout <<std::endl;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif



// void binarySearch(vector<int> ranges,int letter,int m){
//   int left = 0;
//   int right = m;

 
  
// }




int main()
  {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
      freopen("input.txt","r", stdin);
      freopen("output.txt","w", stdout);
    #endif//
    int m,n;
    std::cin >> m >> n;
    vector<int> rooms(m);
    vector<int> letter(n);

    //input for rooms
    for (int i = 0; i < m; i++)
      std::cin >> rooms[i];

    //ip for letter
    for (int i = 0; i < n; i++)
      std::cin >> letter[i];

    //making the ranges
    vector<int> ranges;
    int start = 0;
    for (int i = 0; i < m; i++)
    {
      start += rooms[i];
      ranges.push_back(start);
    }
// 10 25 37
    for (int i = 0; i < n; i++)
    {
    cout <<lower_bound(ranges.begin(),ranges.end(),letter[i])-ranges.begin()+1<<" " <<letter[i]-ranges[lower_bound(ranges.begin(),ranges.end(),letter[i]) - ranges.begin()-1]<<endl;

    }
    return 0;
}

i dont know why but i am getting garbage value when i try to submit the solution on codeforces but it runs correctly on my local machine

Full text and comments »

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

By ClumsyBot, history, 20 months ago, In English

Can someone please tell me what am i doing wrong here?

#include<iostream>
#include<sstream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include<functional>
#include<unordered_map>
#include<numeric>

using namespace std;

#define ll long long
#define mod 1e9+7
#define cy std::cout << "YES"<< std::endl
#define cn std::cout << "NO"<< std::endl
#define IN(x) cin >> x;
#define OUT(x) cout << x;

int solve(int x,int a,int b,int c){//it gives the maximum amount of ribbon when the length is x and we have to substract the length from a,b,c
  if (x < 0)
  {
    return INT_MIN;
  }
    int len1 = solve(x-a,a,b,c)+1;
    int len2 = solve(x-b,a,b,c)+1;
    int len3 = solve(x-c,a,b,c)+1;
  return max({len1,len2,len3});
}


int main()
  {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
      freopen("input.txt","r", stdin);
      freopen("output.txt","w", stdout);
    #endif//
    int length,a,b,c;
    std::cin >> length>>a >>b >>c;
    cout << solve(length,a,b,c);

    return 0;
}

Full text and comments »

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