forked from AASF-IIITM/spojprobs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request AASF-IIITM#37 from source-aasf/master
merge from source-aasf
- Loading branch information
Showing
4 changed files
with
249 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define _ ios_base::sync_with_stdio(false); cin.tie(NULL); | ||
#define ll long long | ||
#define ld long double | ||
#define pb push_back | ||
#define mp make_pair | ||
#define F first | ||
#define S second | ||
|
||
#define PI acos(-1.0) | ||
#define E exp(1.0) | ||
|
||
|
||
|
||
#define fr(i,a,b) for(int i=a; i<b; i++) | ||
#define fr1(i,a,b) for(int i=a; i<=b; i++) | ||
#define rev(i,a,b) for(int i=b; i>=a; i--) | ||
#define foreach(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) | ||
#define FiLL(A, n, val) for(int i=0; i<n; i++) A[i] = val | ||
#define all(x) x.begin(), x.end() | ||
#define apresent(c,x) (find(all(c),x) != (c).end()) | ||
#define T() int tc; cin>>tc; while(tc--) | ||
|
||
|
||
#define max(a,b) ((a)>(b)?(a):(b)) | ||
#define min(a,b) ((a)<(b)?(a):(b)) | ||
|
||
|
||
ll gcd(ll x, ll y) {return y == 0 ? x : gcd(y, x % y);} | ||
ll power(ll x,ll y){ll temp = 1 ;while(y>0){if(y&1) temp = (temp*x);x*=x;y/=2;}return temp;} | ||
ll DigitSum(ll n) {ll temp = 0; n = abs(n); while(n){temp += (n%10); n/=10; } return temp;} | ||
inline ll modexp(ll a,ll b,ll m) { ll d=1; while(b>0) { if(b&1) d=(d*a)%m; a=(a*a)%m; b=b>>1; } return d; } | ||
|
||
|
||
#define INF INT_MAX | ||
#define LINF LONG_LONG_MAX | ||
#define MAX 100007 | ||
#define MOD 1000000007 | ||
|
||
int main() | ||
{ | ||
_ | ||
int n; cin>>n; | ||
int dp[n][2]; | ||
memset(dp, 0, sizeof(dp)); | ||
|
||
int l[n], b[n]; | ||
fr(i, 0, n) | ||
cin>>l[i]>>b[i]; | ||
|
||
fr(i, 0, n) | ||
{ | ||
if(i==0) | ||
{ | ||
dp[0][0] = b[0]; | ||
dp[0][1] = l[0]; | ||
} | ||
else{ | ||
dp[i][0] = b[i] + max(dp[i-1][0] + abs(l[i] - l[i-1]), dp[i-1][1] + abs(l[i] - b[i-1])); | ||
dp[i][1] = l[i] + max(dp[i-1][0] + abs(b[i] - l[i-1]), dp[i-1][1] + abs(b[i] - b[i-1])); | ||
} | ||
} | ||
cout<<max(dp[n-1][0], dp[n-1][1])<<endl; | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define _ ios_base::sync_with_stdio(false); cin.tie(NULL); | ||
#define ll long long | ||
#define ld long double | ||
#define pb push_back | ||
#define mp make_pair | ||
#define F first | ||
#define S second | ||
|
||
#define PI acos(-1.0) | ||
#define E exp(1.0) | ||
|
||
|
||
|
||
#define fr(i,a,b) for(int i=a; i<b; i++) | ||
#define fr1(i,a,b) for(int i=a; i<=b; i++) | ||
#define rev(i,a,b) for(int i=b; i>=a; i--) | ||
#define foreach(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) | ||
#define FiLL(A, n, val) for(int i=0; i<n; i++) A[i] = val | ||
#define all(x) x.begin(), x.end() | ||
#define apresent(c,x) (find(all(c),x) != (c).end()) | ||
#define T() int tc; cin>>tc; while(tc--) | ||
|
||
|
||
#define max(a,b) ((a)>(b)?(a):(b)) | ||
#define min(a,b) ((a)<(b)?(a):(b)) | ||
|
||
|
||
ll gcd(ll x, ll y) {return y == 0 ? x : gcd(y, x % y);} | ||
ll power(ll x,ll y){ll temp = 1 ;while(y>0){if(y&1) temp = (temp*x);x*=x;y/=2;}return temp;} | ||
ll DigitSum(ll n) {ll temp = 0; n = abs(n); while(n){temp += (n%10); n/=10; } return temp;} | ||
inline ll modexp(ll a,ll b,ll m) { ll d=1; while(b>0) { if(b&1) d=(d*a)%m; a=(a*a)%m; b=b>>1; } return d; } | ||
|
||
|
||
#define INF INT_MAX | ||
#define LINF LONG_LONG_MAX | ||
#define MAX 100007 | ||
#define MOD 1000000007 | ||
|
||
bool cmp(const pair<int, pair<int, int> >&i, const pair<int, pair<int, int> >&j) | ||
{ | ||
if (i.F == j.F) | ||
return i.S.F < j.S.F; | ||
return i.F > j.F; | ||
} | ||
|
||
int main() | ||
{ | ||
_ | ||
int n,c; cin>>n>>c; | ||
vector < pair<int, pair<int, int> > > a(n); | ||
map<int, int> m; | ||
fr(i, 0, n) | ||
{ | ||
int s; cin>>s; | ||
if (!m.count(s)) | ||
m[s] = i; | ||
a[m[s]].S.F = m[s]; | ||
a[m[s]].S.S = s; | ||
a[m[s]].F++; | ||
} | ||
|
||
sort(a.begin(), a.end(), cmp); | ||
|
||
fr(i, 0, n) | ||
for (int j = 0; j < a[i].F; j++) | ||
cout<<a[i].S.S<<" "; | ||
|
||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define _ ios_base::sync_with_stdio(false); cin.tie(NULL); | ||
#define ll long long | ||
#define ld long double | ||
#define pb push_back | ||
#define mp make_pair | ||
#define F first | ||
#define S second | ||
|
||
#define PI acos(-1.0) | ||
#define E exp(1.0) | ||
|
||
|
||
|
||
#define fr(i,a,b) for(int i=a; i<b; i++) | ||
#define fr1(i,a,b) for(int i=a; i<=b; i++) | ||
#define rev(i,a,b) for(int i=b; i>=a; i--) | ||
#define foreach(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) | ||
#define FiLL(A, n, val) for(int i=0; i<n; i++) A[i] = val | ||
#define all(x) x.begin(), x.end() | ||
#define apresent(c,x) (find(all(c),x) != (c).end()) | ||
#define T() int tc; cin>>tc; while(tc--) | ||
|
||
|
||
#define max(a,b) ((a)>(b)?(a):(b)) | ||
#define min(a,b) ((a)<(b)?(a):(b)) | ||
|
||
|
||
ll gcd(ll x, ll y) {return y == 0 ? x : gcd(y, x % y);} | ||
ll power(ll x,ll y){ll temp = 1 ;while(y>0){if(y&1) temp = (temp*x);x*=x;y/=2;}return temp;} | ||
ll DigitSum(ll n) {ll temp = 0; n = abs(n); while(n){temp += (n%10); n/=10; } return temp;} | ||
inline ll modexp(ll a,ll b,ll m) { ll d=1; while(b>0) { if(b&1) d=(d*a)%m; a=(a*a)%m; b=b>>1; } return d; } | ||
|
||
|
||
#define INF INT_MAX | ||
#define LINF LONG_LONG_MAX | ||
#define MAX 100007 | ||
#define MOD 1000000007 | ||
|
||
|
||
int dp[2][22][80], o[1000], ni[1000], wt[1000]; | ||
|
||
int main(){ | ||
_ | ||
T(){ | ||
int t, a; | ||
cin>>t>>a; | ||
int n; cin>>n; | ||
|
||
fr(i, 0, n) | ||
cin>>o[i]>>ni[i]>>wt[i]; | ||
|
||
fr1(i, 0, t) | ||
fr1(j, 0, a) | ||
dp[1][i][j] = 1000000; | ||
|
||
dp[1][0][0] = 0; | ||
|
||
for(int i = 0,r = 0;i < n;++i,r ^= 1) | ||
fr1(j, 0, t) | ||
fr1(k, 0, a) | ||
dp[r][j][k] = min(dp[r ^ 1][j][k], wt[i] + dp[r ^ 1][max(0, j-o[i])][max(0,k-ni[i])]); | ||
|
||
printf("%d\n",dp[(n-1) & 1][t][a]); | ||
} | ||
|
||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
char ans[500011], x[500011], y[500011]; | ||
|
||
int main() | ||
{ | ||
int t; cin>>t; | ||
while(t--){ | ||
cin>>x>>y; | ||
int a = strlen(x); | ||
int b = strlen(y); | ||
|
||
int lo = 0, hi = b/a; | ||
int res; | ||
while(lo < hi){ | ||
int mid = lo + (hi-lo+1)/2; | ||
int idx = 0; | ||
|
||
for(int i=0; i<a; i++) | ||
for(int j=1; j<=mid; j++) | ||
ans[idx++] = x[i]; | ||
|
||
int sub = 0; | ||
for(int i=0; sub<idx && i<b; i++) | ||
if(ans[sub] == y[i]) | ||
sub++; | ||
|
||
if(sub == idx) | ||
lo = mid; | ||
else | ||
hi = mid - 1; | ||
} | ||
cout<<lo<<endl; | ||
} | ||
return 0; | ||
} |