Uva 12908 The Book Thief
//Next Codeforces Round #354 (Div. 2)
#include<bits/stdc++.h>
//#include<cstdio>
//#include<iostream>
//#include<algorithm>
//#include<vector>
//#include<cstring>
//#include<cmath>
//#include<map>
using namespace std;
#define fast ios_base::sync_with_stdio(false)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define nl puts("")
//#define i64 long long
#define high 100000005
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
vll v;
void sum()
{
int i;
v.push_back(0);
for(i=1; i<14144 ; i++)
{
v.push_back(v[i-1] + i);
}
}
int khojUpore(int lo, int hi, LL itm)
{
int mid;
while(lo <= hi)
{
mid = (lo + hi) / 2;
if(v[mid] == itm)
{
lo = mid+1;
}
else if(v[mid] > itm)
{
hi=mid-1;
}
else if(v[mid] < itm)
{
lo=mid+1;
}
}
return lo;
}
int main()
{
fast;
sum();
LL s;
while(cin >> s)
{
if(!s)
{
break;
}
int pos = khojUpore(0, v.size()-1, s);
cout << v[pos] - s << " " << pos << "\n";
}
return 0;
}
#include<bits/stdc++.h>
//#include<cstdio>
//#include<iostream>
//#include<algorithm>
//#include<vector>
//#include<cstring>
//#include<cmath>
//#include<map>
using namespace std;
#define fast ios_base::sync_with_stdio(false)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define nl puts("")
//#define i64 long long
#define high 100000005
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
vll v;
void sum()
{
int i;
v.push_back(0);
for(i=1; i<14144 ; i++)
{
v.push_back(v[i-1] + i);
}
}
int khojUpore(int lo, int hi, LL itm)
{
int mid;
while(lo <= hi)
{
mid = (lo + hi) / 2;
if(v[mid] == itm)
{
lo = mid+1;
}
else if(v[mid] > itm)
{
hi=mid-1;
}
else if(v[mid] < itm)
{
lo=mid+1;
}
}
return lo;
}
int main()
{
fast;
sum();
LL s;
while(cin >> s)
{
if(!s)
{
break;
}
int pos = khojUpore(0, v.size()-1, s);
cout << v[pos] - s << " " << pos << "\n";
}
return 0;
}
Comments
Post a Comment